diff options
author | Saketh1499 | 2022-01-27 19:39:53 +0530 |
---|---|---|
committer | Saketh1499 | 2022-01-27 19:39:53 +0530 |
commit | 04c732a7581679b405310d4fb82e37d59adc0e85 (patch) | |
tree | fa69fe2d735863da7bc614acecaf5cffa6375860 | |
parent | fdef4c14b349c177633419f1321c4cd7c9f6c0b5 (diff) | |
download | soul_science_and_concept_map_project-1-04c732a7581679b405310d4fb82e37d59adc0e85.tar.gz soul_science_and_concept_map_project-1-04c732a7581679b405310d4fb82e37d59adc0e85.tar.bz2 soul_science_and_concept_map_project-1-04c732a7581679b405310d4fb82e37d59adc0e85.zip |
First commit
-rwxr-xr-x | abstract_approval.inc | 387 | ||||
-rwxr-xr-x | abstract_bulk_approval.inc | 514 | ||||
-rwxr-xr-x | download.inc | 319 | ||||
-rwxr-xr-x | email.inc | 512 | ||||
-rwxr-xr-x | full_download.inc | 132 | ||||
-rwxr-xr-x | general_deletion.inc | 195 | ||||
-rwxr-xr-x | manage_proposal.inc | 1107 | ||||
-rwxr-xr-x | proposal.inc | 765 | ||||
-rwxr-xr-x | run.inc | 150 | ||||
-rwxr-xr-x | science_and_concept_map.info | 7 | ||||
-rw-r--r-- | science_and_concept_map.install | 618 | ||||
-rwxr-xr-x | science_and_concept_map.module | 966 | ||||
-rwxr-xr-x | science_and_concept_map_details.inc | 100 | ||||
-rwxr-xr-x | settings.inc | 78 | ||||
-rwxr-xr-x | upload_code.inc | 549 | ||||
-rwxr-xr-x | upload_code_delete.inc | 95 |
16 files changed, 6494 insertions, 0 deletions
diff --git a/abstract_approval.inc b/abstract_approval.inc new file mode 100755 index 0000000..118fbb5 --- /dev/null +++ b/abstract_approval.inc @@ -0,0 +1,387 @@ +<?php +// $Id$ +function science_and_concept_map_abstract_approval() + { + /* get a list of unapproved solutions */ + //$pending_solution_q = db_query("SELECT * FROM {soul_science_and_concept_map_solution} WHERE approval_status = 0"); + $query = db_select('soul_science_and_concept_map_solution'); + $query->fields('soul_science_and_concept_map_solution'); + $query->condition('approval_status', 0); + $pending_solution_q = $query->execute(); + if (!$pending_solution_q) + { + drupal_set_message(t('There are no pending code approvals.'), 'status'); + return ''; + } + $pending_solution_rows = array(); + while ($pending_solution_data = $pending_solution_q->fetchObject()) + { + /* get experiment data */ + //$experiment_q = db_query("SELECT * FROM {soul_science_and_concept_map_experiment} WHERE id = %d", $pending_solution_data->experiment_id); + $query = db_select('soul_science_and_concept_map_experiment'); + $query->fields('soul_science_and_concept_map_experiment'); + $query->condition('id', $pending_solution_data->experiment_id); + $experiment_q = $query->execute(); + $experiment_data = $experiment_q->fetchObject(); + /* get proposal data */ + // $proposal_q = db_query("SELECT * FROM {soul_science_and_concept_map_proposal} WHERE id = %d", $experiment_data->proposal_id); + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_proposal'); + $query->condition('id', $experiment_data->proposal_id); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + /* get solution provider details */ + $solution_provider_user_name = ''; + $user_data = user_load($proposal_data->solution_provider_uid); + if ($user_data) + { + $solution_provider_user_name = $user_data->name; + } + else + { + $solution_provider_user_name = ''; + } + /* setting table row information */ + $pending_solution_rows[] = array( + $proposal_data->lab_title, + $experiment_data->title, + $proposal_data->name, + $solution_provider_user_name, + l('Edit', 'science-and-concept-map-project/code-approval/approve/' . $pending_solution_data->id) + ); + } + /* check if there are any pending solutions */ + if (!$pending_solution_rows) + { + drupal_set_message(t('There are no pending solutions'), 'status'); + return ''; + } + $header = array( + 'Title of the Project', + 'Experiment', + 'Proposer', + 'Solution Provider', + 'Actions' + ); + //$output = theme_table($header, $pending_solution_rows); + $output = theme('table', array( + 'header' => $header, + 'rows' => $pending_solution_rows + )); + return $output; + } +function science_and_concept_map_abstract_approval_form($form, &$form_state) + { + $solution_id = (int) arg(3); + /* get solution details */ + //$solution_q = db_query("SELECT * FROM {soul_science_and_concept_map_solution} WHERE id = %d", $solution_id); + $query = db_select('soul_science_and_concept_map_solution'); + $query->fields('soul_science_and_concept_map_solution'); + $query->condition('id', $solution_id); + $solution_q = $query->execute(); + $solution_data = $solution_q->fetchObject(); + if (!$solution_data) + { + drupal_set_message(t('Invalid solution selected.'), 'status'); + drupal_goto('science-and-concept-map-project/code-approval'); + } + if ($solution_data->approval_status == 1) + { + drupal_set_message(t('This solution has already been approved. Are you sure you want to change the approval status?'), 'error'); + } + if ($solution_data->approval_status == 2) + { + drupal_set_message(t('This solution has already been dis-approved. Are you sure you want to change the approval status?'), 'error'); + } + /* get experiment data */ + //xperiment_q = db_query("SELECT * FROM {soul_science_and_concept_map_experiment} WHERE id = %d", $solution_data->experiment_id); + $query = db_select('soul_science_and_concept_map_experiment'); + $query->fields('soul_science_and_concept_map_experiment'); + $query->condition('id', $solution_data->experiment_id); + $experiment_q = $query->execute(); + $experiment_data = $experiment_q->fetchObject(); + /* get proposal data */ + //$proposal_q = db_query("SELECT * FROM {soul_science_and_concept_map_proposal} WHERE id = %d", $experiment_data->proposal_id); + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_proposal'); + $query->condition('id', $experiment_data->proposal_id); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + /* get solution provider details */ + $solution_provider_user_name = ''; + $user_data = user_load($proposal_data->solution_provider_uid); + if ($user_data) + { + $solution_provider_user_name = $user_data->name; + } + else + { + $solution_provider_user_name = ''; + } + $form['#tree'] = TRUE; + $form['lab_title'] = array( + '#type' => 'item', + '#markup' => $proposal_data->lab_title, + '#title' => t('Title of the Project') + ); + $form['name'] = array( + '#type' => 'item', + '#markup' => $proposal_data->name, + '#title' => t('Contributor Name') + ); + $form['experiment']['number'] = array( + '#type' => 'item', + '#markup' => $experiment_data->number, + '#title' => t('Experiment Number') + ); + $form['experiment']['title'] = array( + '#type' => 'item', + '#markup' => $experiment_data->title, + '#title' => t('Title of the Experiment') + ); + $form['back_to_list'] = array( + '#type' => 'item', + '#markup' => l('Back to Code Approval List', 'science-and-concept-map-project/code-approval') + ); + $form['code_number'] = array( + '#type' => 'item', + '#markup' => $solution_data->code_number, + '#title' => t('Code No') + ); + $form['code_caption'] = array( + '#type' => 'item', + '#markup' => $solution_data->caption, + '#title' => t('Caption') + ); + /* get solution files */ + $solution_files_html = ''; + //$solution_files_q = db_query("SELECT * FROM {soul_science_and_concept_map_solution_files} WHERE solution_id = %d ORDER BY id ASC", $solution_id); + $query = db_select('soul_science_and_concept_map_solution_files'); + $query->fields('soul_science_and_concept_map_solution_files'); + $query->condition('solution_id', $solution_id); + $query->orderBy('id', 'ASC'); + $solution_files_q = $query->execute(); + if ($solution_files_q) + { + while ($solution_files_data = $solution_files_q->fetchObject()) + { + $code_file_type = ''; + switch ($solution_files_data->filetype) + { + case 'S': + $code_file_type = 'Source'; + break; + case 'R': + $code_file_type = 'Result'; + break; + case 'X': + $code_file_type = 'Xcox'; + break; + case 'U': + $code_file_type = 'Unknown'; + break; + default: + $code_file_type = 'Unknown'; + break; + } + $solution_files_html .= l($solution_files_data->filename, 'science-and-concept-map-project/download/file/' . $solution_files_data->id) . ' (' . $code_file_type . ')' . '<br/>'; + /*if(strlen($solution_files_data->pdfpath)>=5){ + $pdfname=substr($solution_files_data->pdfpath, strrpos($solution_files_data->pdfpath, '/') + 1); + $solution_files_html .=l($pdfname, 'science-and-concept-map-project/download/pdf/' . $solution_files_data->id). ' (PDF File)' . '<br/>'; + }*/ + } + } + /* get dependencies files */ + //$dependency_q = db_query("SELECT * FROM {soul_science_and_concept_map_solution_dependency} WHERE solution_id = %d ORDER BY id ASC", $solution_id); + $query = db_select('soul_science_and_concept_map_solution_dependency'); + $query->fields('soul_science_and_concept_map_solution_dependency'); + $query->condition('solution_id', $solution_id); + $query->orderBy('id', 'ASC'); + $dependency_q = $query->execute(); + while ($dependency_data = $dependency_q->fetchObject()) + { + //$dependency_files_q = db_query("SELECT * FROM {soul_science_and_concept_map_dependency_files} WHERE id = %d", $dependency_data->dependency_id); + $query = db_select('soul_science_and_concept_map_dependency_files'); + $query->fields('soul_science_and_concept_map_dependency_files'); + $query->condition('id', $dependency_data->dependency_id); + $dependency_files_q = $query->execute(); + $dependency_files_data = $dependency_files_q->fetchObject(); + $solution_file_type = 'Dependency file'; + $solution_files_html .= l($dependency_files_data->filename, 'science-and-concept-map-project/download/dependency/' . $dependency_files_data->id) . ' (' . 'Dependency' . ')' . '<br/>'; + } + $form['solution_files'] = array( + '#type' => 'item', + '#markup' => $solution_files_html, + '#title' => t('Solution') + ); + $form['approved'] = array( + '#type' => 'radios', + '#options' => array( + '0' => 'Pending', + '1' => 'Approved', + '2' => 'Dis-approved (Solution will be deleted)' + ), + '#title' => t('Approval'), + '#default_value' => $solution_data->approval_status + ); + $form['message'] = array( + '#type' => 'textarea', + '#title' => t('Reason for dis-approval'), + '#states' => array( + 'visible' => array( + ':input[name="approved"]' => array( + 'value' => '2' + ) + ), + 'required' => array( + ':input[name="approved"]' => array( + 'value' => '2' + ) + ) + ) + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); + $form['cancel'] = array( + '#type' => 'markup', + '#markup' => l(t('Cancel'), 'soul_science_and_concept_map/code_approval') + ); + return $form; + } +function science_and_concept_map_abstract_approval_form_validate($form, &$form_state) + { + if ($form_state['values']['approved'] == 2) + { + if (strlen(trim($form_state['values']['message'])) <= 30) + { + form_set_error('message', t('Please mention the reason for disapproval.')); + } + } + return; + } +function science_and_concept_map_abstract_approval_form_submit($form, &$form_state) + { + global $user; + $solution_id = (int) arg(3); + /* get solution details */ + //$solution_q = db_query("SELECT * FROM {soul_science_and_concept_map_solution} WHERE id = %d", $solution_id); + $query = db_select('soul_science_and_concept_map_solution'); + $query->fields('soul_science_and_concept_map_solution'); + $query->condition('id', $solution_id); + $solution_q = $query->execute(); + $solution_data = $solution_q->fetchObject(); + if (!$solution_data) + { + drupal_set_message(t('Invalid solution selected.'), 'status'); + drupal_goto('soul_science_and_concept_map/code_approval'); + } + /* get experiment data */ + //$experiment_q = db_query("SELECT * FROM {soul_science_and_concept_map_experiment} WHERE id = %d", $solution_data->experiment_id); + $query = db_select('soul_science_and_concept_map_experiment'); + $query->fields('soul_science_and_concept_map_experiment'); + $query->condition('id', $solution_data->experiment_id); + $experiment_q = $query->execute(); + $experiment_data = $experiment_q->fetchObject(); + /* get proposal data */ + //$proposal_q = db_query("SELECT * FROM {soul_science_and_concept_map_proposal} WHERE id = %d", $experiment_data->proposal_id); + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_proposal'); + $query->condition('id', $experiment_data->proposal_id); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + $user_data = user_load($proposal_data->uid); + $solution_prove_user_data = user_load($proposal_data->solution_provider_uid); + // **** TODO **** : del_lab_pdf($proposal_data->id); + if ($form_state['values']['approved'] == "0") + { + $query = "UPDATE {soul_science_and_concept_map_solution} SET approval_status = 0, approver_uid = :approver_uid, approval_date = :approval_date WHERE id = :solution_id"; + $args = array( + ":approver_uid" => $user->uid, + ":approval_date" => time(), + ":solution_id" => $solution_id + ); + db_query($query, $args); + /* sending email */ + $email_to = $user_data->mail; + $from = variable_get('soul_science_and_concept_map_from_email', ''); + $bcc = variable_get('soul_science_and_concept_map_emails', ''); + $cc = variable_get('soul_science_and_concept_map_cc_emails', ''); + $param['solution_pending']['solution_id'] = $solution_id; + $param['solution_pending']['user_id'] = $user_data->uid; + $param['solution_pending']['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('soul_science_and_concept_map', 'solution_pending', $email_to, language_default(), $param, $from, TRUE)) + drupal_set_message('Error sending email message.', 'error'); + } + else if ($form_state['values']['approved'] == "1") + { + $query = "UPDATE {soul_science_and_concept_map_solution} SET approval_status = 1, approver_uid = :approver_uid, approval_date = :approval_date WHERE id = :solution_id"; + $args = array( + ":approver_uid" => $user->uid, + ":approval_date" => time(), + ":solution_id" => $solution_id + ); + db_query($query, $args); + /* sending email */ + $email_to = $user_data->mail; + $from = variable_get('soul_science_and_concept_map_from_email', ''); + $bcc = variable_get('soul_science_and_concept_map_emails', ''); + $cc = variable_get('soul_science_and_concept_map_cc_emails', ''); + $param['solution_approved']['solution_id'] = $solution_id; + $param['solution_approved']['user_id'] = $user_data->uid; + $param['solution_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('soul_science_and_concept_map', 'solution_approved', $email_to, language_default(), $param, $from, TRUE)) + drupal_set_message('Error sending email message.', 'error'); + } + else if ($form_state['values']['approved'] == "2") + { + if (soul_science_and_concept_map_delete_solution($solution_id)) + { + /* sending email */ + $email_to = $user_data->mail; + $from = variable_get('soul_science_and_concept_map_from_email', ''); + $bcc = variable_get('soul_science_and_concept_map_emails', ''); + $cc = variable_get('soul_science_and_concept_map_cc_emails', ''); + $param['solution_disapproved']['experiment_number'] = $experiment_data->number; + $param['solution_disapproved']['experiment_title'] = $experiment_data->title; + $param['solution_disapproved']['solution_number'] = $solution_data->code_number; + $param['solution_disapproved']['solution_caption'] = $solution_data->caption; + $param['solution_disapproved']['user_id'] = $user_data->uid; + $param['solution_disapproved']['message'] = $form_state['values']['message']; + $param['solution_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('soul_science_and_concept_map', 'solution_disapproved', $email_to, language_default(), $param, $from, TRUE)) + drupal_set_message('Error sending email message.', 'error'); + } + else + { + drupal_set_message('Error disapproving and deleting solution. Please contact administrator.', 'error'); + } + } + drupal_set_message('Updated successfully.', 'status'); + drupal_goto('science-and-concept-map-project/code-approval'); + }
\ No newline at end of file diff --git a/abstract_bulk_approval.inc b/abstract_bulk_approval.inc new file mode 100755 index 0000000..2c33c80 --- /dev/null +++ b/abstract_bulk_approval.inc @@ -0,0 +1,514 @@ +<?php + +function science_and_concept_map_abstract_bulk_approval_form($form, &$form_state) +{ + $options_first = _bulk_list_of_science_and_concept_map_project(); + $selected = isset($form_state['values']['science_and_concept_map_project']) ? $form_state['values']['science_and_concept_map_project'] : key($options_first); + $form = array(); + $form['science_and_concept_map_project'] = array( + '#type' => 'select', + '#title' => t('Title of the science and concept map project'), + '#options' => _bulk_list_of_science_and_concept_map_project(), + '#default_value' => $selected, + '#ajax' => array( + + 'callback' => 'ajax_bulk_science_and_concept_map_abstract_details_callback' + ), + '#suffix' => '<div id="ajax_selected_science_and_concept_map"></div><div id="ajax_selected_science_and_concept_map_pdf"></div>' + ); + $form['science_and_concept_map_actions'] = array( + '#type' => 'select', + '#title' => t('Please select action for science and concept map project'), + '#options' => _bulk_list_science_and_concept_map_actions(), + '#default_value' => 0, + '#prefix' => '<div id="ajax_selected_science_and_concept_map_action" style="color:red;">', + '#suffix' => '</div>', + '#states' => array( + 'invisible' => array( + ':input[name="science_and_concept_map_project"]' => array( + 'value' => 0 + ) + ) + ) + ); + $form['message'] = array( + '#type' => 'textarea', + '#title' => t('Please specify the reason for Resubmission / Dis-Approval'), + '#prefix' => '<div id= "message_submit">', + '#states' => array( + 'visible' => array( + array( + ':input[name="science_and_concept_map_actions"]' => array( + 'value' => 3 + ) + ), + 'or', + array( + ':input[name="science_and_concept_map_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_science_and_concept_map_abstract_details_callback($form, $form_state) +{ + $commands = array(); + $science_and_concept_map_project_default_value = $form_state['values']['science_and_concept_map_project']; + if ($science_and_concept_map_project_default_value != 0) + { + $commands[] = ajax_command_html('#ajax_selected_science_and_concept_map', _science_and_concept_map_details($science_and_concept_map_project_default_value)); + $form['science_and_concept_map_actions']['#options'] = _bulk_list_science_and_concept_map_actions(); + $commands[] = ajax_command_replace('#ajax_selected_science_and_concept_map_action', drupal_render($form['science_and_concept_map_actions'])); + } //$science_and_concept_map_project_default_value != 0 + else + { + $commands[] = ajax_command_html('#ajax_selected_science_and_concept_map', ''); + $commands[] = ajax_command_data('#ajax_selected_science_and_concept_map', 'form_state_value_select', $form_state['values']['science_and_concept_map_project']); + } + return array( + '#type' => 'ajax', + '#commands' => $commands + ); +} +/************************************************************/ +function science_and_concept_map_abstract_bulk_approval_form_submit($form, &$form_state) +{ + global $user; + $msg = ''; + $root_path = science_and_concept_map_document_path(); + if ($form_state['clicked_button']['#value'] == 'Submit') + { + if ($form_state['values']['science_and_concept_map_project']) + // science_and_concept_map_abstract_del_lab_pdf($form_state['values']['science_and_concept_map_project']); + if (user_access('soul science and concept map bulk manage abstract')) + { + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_proposal'); + $query->condition('id', $form_state['values']['science_and_concept_map_project']); + $user_query = $query->execute(); + $user_info = $user_query->fetchObject(); + $user_data = user_load($user_info->uid); + if ($form_state['values']['science_and_concept_map_actions'] == 1) + { + // approving entire project // + $query = db_select('soul_science_and_concept_map_submitted_abstracts'); + $query->fields('soul_science_and_concept_map_submitted_abstracts'); + $query->condition('proposal_id', $form_state['values']['science_and_concept_map_project']); + $abstracts_q = $query->execute(); + $experiment_list = ''; + while ($abstract_data = $abstracts_q->fetchObject()) + { + db_query("UPDATE {soul_science_and_concept_map_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 {soul_science_and_concept_map_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 science and concept map project.'), 'status'); + // email + $email_subject = t('[!site_name][Science and Concept Map Project] Your uploaded project files for science and concept map project have been approved', array( + '!site_name' => variable_get('site_name', '') + )); + $email_body = array( + 0 => t(' + +Dear !user_name, + +Your uploaded report and project files for the science and concept map project has been approved: + +Full Name : ' . $user_info->name_title . ' ' . $user_info->contributor_name . ' +Title of science and concept map project : ' . $user_info->project_title . ' +Title of Category : ' . $user_info->category . ' + +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('science_and_concept_map_from_email', ''); + $bcc = variable_get('science_and_concept_map_emails', ''); + $cc = variable_get('science_and_concept_map_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('science_and_concept_map', 'standard', $email_to, language_default(), $params, $from, TRUE)) + { + $msg = drupal_set_message('Error sending email message.', 'error'); + } //!drupal_mail('science_and_concept_map', 'standard', $email_to, language_default(), $params, $from, TRUE) + } //$form_state['values']['science_and_concept_map_actions'] == 1 + elseif ($form_state['values']['science_and_concept_map_actions'] == 2) + { + if (strlen(trim($form_state['values']['message'])) <= 30) + { + form_set_error('message', t('')); + $msg = drupal_set_message("Please mention the reason for resubmission. Minimum 30 character required", 'error'); + return $msg; + } + //pending review entire project + $query = db_select('soul_science_and_concept_map_submitted_abstracts'); + $query->fields('soul_science_and_concept_map_submitted_abstracts'); + $query->condition('proposal_id', $form_state['values']['science_and_concept_map_project']); + $abstracts_q = $query->execute(); + $experiment_list = ''; + while ($abstract_data = $abstracts_q->fetchObject()) + { + db_query("UPDATE {soul_science_and_concept_map_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 {soul_science_and_concept_map_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 {soul_science_and_concept_map_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][Science and Concept Map Project] Your uploaded science and concept map 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 . 'after making changes considering the following reviewer’s comments. + +Comment: ' . $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('science_and_concept_map_from_email', ''); + $bcc = variable_get('science_and_concept_map_emails', ''); + $cc = variable_get('science_and_concept_map_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('science_and_concept_map', 'standard', $email_to, language_default(), $params, $from, TRUE)) + { + drupal_set_message('Error sending email message.', 'error'); + } //!drupal_mail('science_and_concept_map', 'standard', $email_to, language_default(), $params, $from, TRUE) + } //$form_state['values']['science_and_concept_map_actions'] == 2 + elseif ($form_state['values']['science_and_concept_map_actions'] == 3) //disapprove and delete entire science and concept map 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('soul science and concept map bulk delete abstract')) + { + $msg = drupal_set_message(t('You do not have permission to Bulk Dis-Approved and Deleted Entire Project.'), 'error'); + return $msg; + } //!user_access('science_and_concept_map bulk delete code') + if (science_and_concept_map_abstract_delete_project($form_state['values']['science_and_concept_map_project'])) ////// + { + drupal_set_message(t('Dis-Approved and Deleted Entire science and concept map project.'), 'status'); + $email_subject = t('[!site_name][Science and Concept Map Project] Your uploaded science and concept map project have been marked as dis-approved', array( + '!site_name' => variable_get('site_name', '') + )); + $email_body = array( + 0 => t(' + +Dear !user_name, + +Your uploaded science and concept map project files for the science and concept map 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('science_and_concept_map_from_email', ''); + $bcc = variable_get('science_and_concept_map_emails', ''); + $cc = variable_get('science_and_concept_map_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('science_and_concept_map', 'standard', $email_to, language_default(), $params, $from, TRUE)) + { + drupal_set_message('Error sending email message.', 'error'); + } + } //science_and_concept_map_abstract_delete_project($form_state['values']['science_and_concept_map_project']) + else + { + drupal_set_message(t('Error Dis-Approving and Deleting Entire science and concept map project.'), 'error'); + } + // email + + } //$form_state['values']['science_and_concept_map_actions'] == 3 + /*elseif ($form_state['values']['science_and_concept_map_actions'] == 4) + { + if (strlen(trim($form_state['values']['message'])) <= 30) + { + form_set_error('message', t('')); + $msg = drupal_set_message("Please mention the reason for disapproval/deletion. Minimum 30 character required", 'error'); + return $msg; + } //strlen(trim($form_state['values']['message'])) <= 30 + $query = db_select('soul_science_and_concept_map_abstract_experiment'); + $query->fields('soul_science_and_concept_map_abstract_experiment'); + $query->condition('proposal_id', $form_state['values']['lab']); + $query->orderBy('number', 'ASC'); + $experiment_q = $query->execute(); + $experiment_list = ''; + while ($experiment_data = $experiment_q->fetchObject()) + { + $experiment_list .= '<p>' . $experiment_data->number . ') ' . $experiment_data->title . '<br> Description : ' . $experiment_data->description . '<br>'; + $experiment_list .= ' '; + $experiment_list .= '</p>'; + } //$experiment_data = $experiment_q->fetchObject() + if (!user_access('lab migration bulk delete code')) + { + $msg = drupal_set_message(t('You do not have permission to Bulk Delete Entire Lab Including Proposal.'), 'error'); + return $msg; + } //!user_access('lab migration bulk delete code') + // check if dependency files are present + $dep_q = db_query("SELECT * FROM {soul_science_and_concept_map_abstract_dependency_files} WHERE proposal_id = :proposal_id", array( + ":proposal_id" => $form_state['values']['lab'] + )); + if ($dep_data = $dep_q->fetchObject()) + { + $msg = drupal_set_message(t("Cannot delete lab since it has dependency files that can be used by others. First delete the dependency files before deleting the lab."), 'error'); + return $msg ; + } //$dep_data = $dep_q->fetchObject() + if (science_and_concept_map_abstract_delete_lab($form_state['values']['lab'])) + { + drupal_set_message(t('Dis-Approved and Deleted Entire Lab solutions.'), 'status'); + $query = db_select('soul_science_and_concept_map_abstract_experiment'); + $query->fields('soul_science_and_concept_map_abstract_experiment'); + $query->condition('proposal_id', $form_state['values']['lab']); + $experiment_q = $query->execute()->fetchObject(); + $dir_path = $root_path . $experiment_q->directory_name; + if (is_dir($dir_path)) + { + $res = rmdir($dir_path); + if (!$res) + { + $msg = drupal_set_message(t("Cannot delete Lab directory : " . $dir_path . ". Please contact administrator."), 'error'); + return $msg; + } //!$res + } //is_dir($dir_path) + else + { + drupal_set_message(t("Lab directory not present : " . $dir_path . ". Skipping deleting lab directory."), 'status'); + } + $proposal_q = db_query("SELECT * FROM {soul_science_and_concept_map_abstract_proposal} WHERE id = :id", array( + ":id" => $form_state['values']['lab'] + )); + $proposal_data = $proposal_q->fetchObject(); + $proposal_id = $proposal_data->id; + db_query("DELETE FROM {soul_science_and_concept_map_abstract_experiment} WHERE proposal_id = :proposal_id", array( + ":proposal_id" => $proposal_id + )); + db_query("DELETE FROM {soul_science_and_concept_map_abstract_proposal} WHERE id = :id", array( + ":id" => $proposal_id + )); + drupal_set_message(t('Deleted Lab Proposal.'), 'status'); + //email + $email_subject = t('[!site_name] Your uploaded Lab Migration solutions including the Lab proposal have been deleted', array( + '!site_name' => variable_get('site_name', '') + )); + $email_body = array( + 0 => t(' + +Dear !user_name, + +We regret to inform you that all the uploaded Experiments of your Lab with following details have been deleted permanently. + +Title of Lab :' . $user_info->lab_title . ' + +List of experiments : ' . $experiment_list . ' + +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 + // $email_subject = t('Your uploaded Lab Migration solutions including the Lab proposal have been deleted'); + $email_body = array( + 0 => t('Your all the uploaded solutions including the Lab proposal have been deleted permanently.') + ); + } //science_and_concept_map_abstract_delete_lab($form_state['values']['lab']) + else + { + $msg = drupal_set_message(t('Error Dis-Approving and Deleting Entire Lab.'), 'error'); + } + } //$form_state['values']['science_and_concept_map_actions'] == 4 + else + { + $msg = drupal_set_message(t('You do not have permission to bulk manage code.'), 'error'); + }*/ + } //user_access('science_and_concept_map project bulk manage code') + return $msg; + } //$form_state['clicked_button']['#value'] == 'Submit' +} +/**********************************************************/ +function _bulk_list_of_science_and_concept_map_project() +{ + $project_titles = array( + '0' => 'Please select...' + ); + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_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_science_and_concept_map_actions() +{ + $science_and_concept_map_actions = array( + 0 => 'Please select...' + ); + $science_and_concept_map_actions[1] = 'Approve Entire science and concept map Project'; + $science_and_concept_map_actions[2] = 'Resubmit Project files'; + $science_and_concept_map_actions[3] = 'Dis-Approve Entire science and concept map Project (This will delete science and concept map Project)'; + //$science_and_concept_map_actions[4] = 'Delete Entire science and concept map Project Including Proposal'; + return $science_and_concept_map_actions; +} +function _science_and_concept_map_details($science_and_concept_map_proposal_id) +{ + $return_html = ""; + $query_pro = db_select('soul_science_and_concept_map_proposal'); + $query_pro->fields('soul_science_and_concept_map_proposal'); + $query_pro->condition('id', $science_and_concept_map_proposal_id); + $abstracts_pro = $query_pro->execute()->fetchObject(); + //var_dump($abstracts_pro);die; + $query_pdf = db_select('soul_science_and_concept_map_submitted_abstracts_file'); + $query_pdf->fields('soul_science_and_concept_map_submitted_abstracts_file'); + $query_pdf->condition('proposal_id', $science_and_concept_map_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('soul_science_and_concept_map_submitted_abstracts_file'); + $query_process->fields('soul_science_and_concept_map_submitted_abstracts_file'); + $query_process->condition('proposal_id', $science_and_concept_map_proposal_id); + $query_process->condition('filetype', 'S'); + $abstracts_query_process = $query_process->execute()->fetchObject(); + $query = db_select('soul_science_and_concept_map_submitted_abstracts'); + $query->fields('soul_science_and_concept_map_submitted_abstracts'); + $query->condition('proposal_id', $science_and_concept_map_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', 'science-and-concept-map-project/abstract-code/upload'); + $abstracts_query_process_filename = "File not uploaded"; + } + $download_science_and_concept_map = l('Download science and concept map project','science-and-concept-map-project/full-download/project/'.$science_and_concept_map_proposal_id); + $return_html .= '<strong>Proposer Name:</strong><br />' . $abstracts_pro->name_title . ' ' . $abstracts_pro->contributor_name . '<br /><br />'; + $return_html .= '<strong>Title of the science and concept map Project:</strong><br />' . $abstracts_pro->project_title . '<br /><br />'; + $return_html .= '<strong>Title of the Category:</strong><br />' . $abstracts_pro->category . '<br /><br />'; + $return_html .= '<strong>Uploaded a Report (brief outline) of the project:</strong><br />' . $abstract_filename . '<br /><br />'; + $return_html .= '<strong>Upload the soul science and concept map project code files for the proposal:</strong><br />' . $abstracts_query_process_filename . '<br /><br />'; + $return_html .= $download_science_and_concept_map; + return $return_html; +}
\ No newline at end of file diff --git a/download.inc b/download.inc new file mode 100755 index 0000000..6b79fa3 --- /dev/null +++ b/download.inc @@ -0,0 +1,319 @@ +<?php +// $Id$ +function science_and_concept_map_download_upload_file() +{ + $proposal_id = arg(3); + $root_path = science_and_concept_map_document_path(); + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_proposal'); + $query->condition('id', $proposal_id); + $query->range(0, 1); + $result = $query->execute(); + $science_and_concept_map_upload_file = $result->fetchObject(); + $samplecodename = substr($science_and_concept_map_upload_file->abstractfilepath, strrpos($science_and_concept_map_upload_file->abstractfilepath, '/') + 1); + 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="' . $samplecodename . '"'); + header('Content-Length: ' . filesize($root_path . $science_and_concept_map_upload_file->abstractfilepath)); + header("Content-Transfer-Encoding: binary"); + header('Expires: 0'); + header('Pragma: no-cache'); + ob_clean(); + readfile($root_path . $science_and_concept_map_upload_file->abstractfilepath); + //ob_end_flush(); + + //flush(); +} +function soul_science_and_concept_map_project_files() { + $proposal_id = arg(3); + $root_path = science_and_concept_map_document_path(); + $query = db_select('soul_science_and_concept_map_submitted_abstracts_file'); + $query->fields('soul_science_and_concept_map_submitted_abstracts_file'); + $query->condition('proposal_id', $proposal_id); + $result = $query->execute(); + $soul_science_and_concept_map_project_files = $result->fetchObject(); + //var_dump($soul_science_and_concept_map_project_files);die; + $query1 = db_select('soul_science_and_concept_map_proposal'); + $query1->fields('soul_science_and_concept_map_proposal'); + $query1->condition('id', $proposal_id); + $result1 = $query1->execute(); + $science_and_concept_map = $result1->fetchObject(); + $directory_name = $science_and_concept_map->directory_name . '/project_files/'; + $samplecodename = $soul_science_and_concept_map_project_files->filename; + 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="' . $samplecodename . '"'); + header("Content-Length: " . filesize($root_path . $directory_name . $samplecodename)); + header("Content-Transfer-Encoding: binary"); + header("Expires: 0"); + header("Pragma: no-cache"); + ob_clean(); + readfile($root_path . $directory_name . $samplecodename); + //ob_end_flush(); + //ob_clean(); +} +/* +function science_and_concept_map_download_solution_file() +{ + $solution_file_id = arg(3); + $root_path = science_and_concept_map_path(); + // $solution_files_q = db_query("SELECT * FROM {science_and_concept_map_solution_files} WHERE id = %d LIMIT 1", $solution_file_id); + $solution_files_q = db_query("SELECT lmsf.*, lmp.directory_name FROM soul_science_and_concept_map_solution_files lmsf JOIN soul_science_and_concept_map_solution lms JOIN soul_science_and_concept_map_experiment lme JOIN soul_science_and_concept_map_proposal lmp WHERE lms.id = lmsf.solution_id AND lme.id = lms.experiment_id AND lmp.id = lme.proposal_id AND lmsf.id = :solution_id LIMIT 1", array( + ':solution_id' => $solution_file_id + )); + $solution_file_data = $solution_files_q->fetchObject(); + header('Content-Type: ' . $solution_file_data->filemime); + //header('Content-Type: application/octet-stram'); + header('Content-disposition: attachment; filename="' . str_replace(' ', '_', ($solution_file_data->filename)) . '"'); + header('Content-Length: ' . filesize($root_path . $solution_file_data->directory_name . '/' . $solution_file_data->filepath)); + readfile($root_path . $solution_file_data->directory_name . '/' . $solution_file_data->filepath); +} +function science_and_concept_map_download_dependency_file() +{ + $dependency_file_id = arg(3); + $root_path = science_and_concept_map_path(); + //$dependency_file_q = db_query("SELECT * FROM {science_and_concept_map_dependency_files} WHERE id = %d LIMIT 1", $dependency_file_id); + $query = db_select('soul_science_and_concept_map_dependency_files'); + $query->fields('soul_science_and_concept_map_dependency_files'); + $query->condition('id', $dependency_file_id); + $query->range(0, 1); + $dependency_files_q = $query->execute(); + $dependency_file_data = $dependency_files_q->fetchObject(); + header('Content-Type: ' . $dependency_file_data->filemime); + header('Content-disposition: attachment; filename="' . str_replace(' ', '_', ($dependency_file_data->filename)) . '"'); + header('Content-Length: ' . filesize($root_path . $dependency_file_data->filepath)); + readfile($root_path . $dependency_file_data->filepath); +} +function science_and_concept_map_download_solution() +{ + $solution_id = arg(3); + $root_path = science_and_concept_map_path(); + $query = db_select('soul_science_and_concept_map_solution'); + $query->fields('soul_science_and_concept_map_solution'); + $query->condition('id', $solution_id); + $solution_q = $query->execute(); + $solution_data = $solution_q->fetchObject(); + $query = db_select('soul_science_and_concept_map_experiment'); + $query->fields('soul_science_and_concept_map_experiment'); + $query->condition('id', $solution_data->experiment_id); + $experiment_q = $query->execute(); + $experiment_data = $experiment_q->fetchObject(); + $solution_files_q = db_query("SELECT lmsf.*, lmp.directory_name FROM soul_science_and_concept_map_solution_files lmsf JOIN soul_science_and_concept_map_solution lms JOIN soul_science_and_concept_map_experiment lme JOIN soul_science_and_concept_map_proposal lmp WHERE lms.id = lmsf.solution_id AND lme.id = lms.experiment_id AND lmp.id = lme.proposal_id AND lmsf.id = :solution_id", array( + ':solution_id' => $solution_id + )); + $query = db_select('soul_soul_science_and_concept_map_solution_dependency'); + $query->fields('soul_science_and_concept_map_solution_dependency'); + $query->condition('solution_id', $solution_id); + $solution_dependency_files_q = $query->execute(); + $CODE_PATH = 'CODE' . $solution_data->code_number . '/'; + /* zip filename */ + //$zip_filename = $root_path . 'zip-' . time() . '-' . rand(0, 999999) . '.zip'; + /* creating zip archive on the server */ + /*$zip = new ZipArchive; + $zip->open($zip_filename, ZipArchive::CREATE); + while ($solution_files_row = $solution_files_q->fetchObject()) + { + $zip->addFile($root_path . $solution_files_row->directory_name . '/' . $solution_files_row->filepath, $CODE_PATH . str_replace(' ', '_', ($solution_files_row->filename))); + } //$solution_files_row = $solution_files_q->fetchObject() + /* dependency files */ + /*while ($solution_dependency_files_row = $solution_dependency_files_q->fetchObject()) + { + $query = db_select('soul_science_and_concept_map_dependency_files'); + $query->fields('soul_science_and_concept_map_dependency_files'); + $query->condition('id', $solution_dependency_files_row->dependency_id); + $query->range(0, 1); + $dependency_file_data = $query->execute()->fetchObject(); + if ($dependency_file_data) + $zip->addFile($root_path . $dependency_file_data->filepath, $CODE_PATH . 'DEPENDENCIES/' . str_replace(' ', '_', ($dependency_file_data->filename))); + } //$solution_dependency_files_row = $solution_dependency_files_q->fetchObject() + $zip_file_count = $zip->numFiles; + $zip->close(); + if ($zip_file_count > 0) + { + /* download zip file */ + /*header('Content-Type: application/zip'); + header('Content-disposition: attachment; filename="CODE' . $solution_data->code_number . '.zip"'); + header('Content-Length: ' . filesize($zip_filename)); + ob_clean(); + //flush(); + readfile($zip_filename); + unlink($zip_filename); + } //$zip_file_count > 0 + else + { + drupal_set_message("There are no files in this solutions to download", 'error'); + drupal_goto('science-and-concept-map-project/science-and-concept-map-project-run'); + } +} +function science_and_concept_map_download_experiment() +{ + $experiment_id = (int) arg(3); + $root_path = science_and_concept_map_path(); + /* get solution data */ +/* $query = db_select('soul_science_and_concept_map_experiment'); + $query->fields('soul_science_and_concept_map_experiment'); + $query->condition('id', $experiment_id); + $experiment_q = $query->execute(); + $experiment_data = $experiment_q->fetchObject(); + $EXP_PATH = 'EXP' . $experiment_data->number . '/'; + /* zip filename */ + //$zip_filename = $root_path . 'zip-' . time() . '-' . rand(0, 999999) . '.zip'; + /* creating zip archive on the server */ + /*$zip = new ZipArchive; + $zip->open($zip_filename, ZipArchive::CREATE); + $query = db_select('soul_science_and_concept_map_solution'); + $query->fields('soul_science_and_concept_map_solution'); + $query->condition('experiment_id', $experiment_id); + $query->condition('approval_status', 1); + $solution_q = $query->execute(); + while ($solution_row = $solution_q->fetchObject()) + { + $CODE_PATH = 'CODE' . $solution_row->code_number . '/'; + $solution_files_q = db_query("SELECT lmsf.*, lmp.directory_name FROM soul_science_and_concept_map_solution_files lmsf JOIN soul_science_and_concept_map_solution lms JOIN soul_science_and_concept_map_experiment lme JOIN soul_science_and_concept_map_proposal lmp WHERE lms.id = lmsf.solution_id AND lme.id = lms.experiment_id AND lmp.id = lme.proposal_id AND lmsf.solution_id = :solution_id", array( + ':solution_id' => $solution_row->id + )); + while ($solution_files_row = $solution_files_q->fetchObject()) + { + $zip->addFile($root_path . $solution_files_row->directory_name . '/' . $solution_files_row->filepath, $EXP_PATH . $CODE_PATH . str_replace(' ', '_', ($solution_files_row->filename))); + } //$solution_files_row = $solution_files_q->fetchObject() + /* dependency files */ + /* $query = db_select('soul_science_and_concept_map_solution_dependency'); + $query->fields('soul_science_and_concept_map_solution_dependency'); + $query->condition('solution_id', $solution_row->id); + $solution_dependency_files_q = $query->execute(); + while ($solution_dependency_files_row = $solution_dependency_files_q->fetchObject()) + { + $query = db_select('soul_science_and_concept_map_dependency_files'); + $query->fields('soul_science_and_concept_map_dependency_files'); + $query->condition('id', $solution_dependency_files_row->dependency_id); + $query->range(0, 1); + $dependency_file_data = $query->execute()->fetchObject(); + if ($dependency_file_data) + $zip->addFile($root_path . $dependency_file_data->filepath, $EXP_PATH . $CODE_PATH . 'DEPENDENCIES/' . str_replace(' ', '_', ($dependency_file_data->filename))); + } //$solution_dependency_files_row = $solution_dependency_files_q->fetchObject() + } //$solution_row = $solution_q->fetchObject() + $zip_file_count = $zip->numFiles; + $zip->close(); + if ($zip_file_count > 0) + { + /* download zip file */ + /* header('Content-Type: application/zip'); + header('Content-disposition: attachment; filename="EXP' . $experiment_data->number . '.zip"'); + header('Content-Length: ' . filesize($zip_filename)); + ob_clean(); + //flush(); + readfile($zip_filename); + unlink($zip_filename); + } //$zip_file_count > 0 + else + { + drupal_set_message("There are no solutions in this experiment to download", 'error'); + drupal_goto('science-and-concept-map-project/science-and-concept-map-project-run'); + } +} +function science_and_concept_map_download_project() +{ + global $user; + $lab_id = arg(3); + $root_path = science_and_concept_map_path(); + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_proposal'); + $query->condition('id', $lab_id); + $lab_q = $query->execute(); + $lab_data = $lab_q->fetchObject(); + $LAB_PATH = $lab_data->lab_title . '/'; + /* 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('soul_science_and_concept_map_experiment'); + $query->fields('soul_science_and_concept_map_experiment'); + $query->condition('proposal_id', $lab_id); + $experiment_q = $query->execute(); + while ($experiment_row = $experiment_q->fetchObject()) + { + $EXP_PATH = 'EXP' . $experiment_row->number . '/'; + //$solution_q = db_query("SELECT * FROM {science_and_concept_map_solution} WHERE experiment_id = %d AND approval_status = 1", $experiment_row->id); + $query = db_select('soul_science_and_concept_map_solution'); + $query->fields('soul_science_and_concept_map_solution'); + $query->condition('experiment_id', $experiment_row->id); + $query->condition('approval_status', 1); + $solution_q = $query->execute(); + while ($solution_row = $solution_q->fetchObject()) + { + $CODE_PATH = 'CODE' . $solution_row->code_number . '/'; + //$solution_files_q = db_query("SELECT * FROM {science_and_concept_map_solution_files} WHERE solution_id = %d", $solution_row->id); + $solution_files_q = db_query("SELECT lmsf.*, lmp.directory_name FROM soul_science_and_concept_map_solution_files lmsf JOIN soul_science_and_concept_map_solution lms JOIN soul_science_and_concept_map_experiment lme JOIN soul_science_and_concept_map_proposal lmp WHERE lms.id = lmsf.solution_id AND lme.id = lms.experiment_id AND lmp.id = lme.proposal_id AND lmsf.id = :solution_id", array( + ':solution_id' => $solution_row->id + )); + $query = db_select('soul_science_and_concept_map_solution_dependency'); + $query->fields('soul_science_and_concept_map_solution_dependency'); + $query->condition('solution_id', $solution_row->id); + $solution_dependency_files_q = $query->execute(); + while ($solution_files_row = $solution_files_q->fetchObject()) + { + $zip->addFile($root_path . $solution_files_row->directory_name . '/' . $solution_files_row->filepath, $EXP_PATH . $CODE_PATH . str_replace(' ', '_', ($solution_files_row->filename))); + //var_dump($zip->numFiles); + } //$solution_files_row = $solution_files_q->fetchObject() + // die; + /* dependency files */ + /* while ($solution_dependency_files_row = $solution_dependency_files_q->fetchObject()) + { + //$dependency_file_data = (db_query("SELECT * FROM {science_and_concept_map_dependency_files} WHERE id = %d LIMIT 1", $solution_dependency_files_row->dependency_id))->fetchObject(); + $query = db_select('soul_science_and_concept_map_dependency_files'); + $query->fields('soul_science_and_concept_map_dependency_files'); + $query->condition('id', $solution_dependency_files_row->dependency_id); + $query->range(0, 1); + $dependency_file_data = $query->execute()->fetchObject(); + if ($dependency_file_data) + $zip->addFile($root_path . $dependency_file_data->filepath, $EXP_PATH . $CODE_PATH . 'DEPENDENCIES/' . str_replace(' ', '_', ($dependency_file_data->filename))); + } //$solution_dependency_files_row = $solution_dependency_files_q->fetchObject() + } //$solution_row = $solution_q->fetchObject() + } //$experiment_row = $experiment_q->fetchObject() + $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(' ', '_', $lab_data->lab_title) . '.zip"'); + header('Content-Length: ' . filesize($zip_filename)); + ob_clean(); + //flush(); + readfile($zip_filename); + unlink($zip_filename); + } //$user->uid + else + { + header('Content-Type: application/zip'); + header('Content-disposition: attachment; filename="' . str_replace(' ', '_', $lab_data->lab_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 solutions in this Lab to download", 'error'); + drupal_goto('science-and-concept-map-project/science-and-concept-map-project-run'); + } +}*/
\ No newline at end of file diff --git a/email.inc b/email.inc new file mode 100755 index 0000000..286aaad --- /dev/null +++ b/email.inc @@ -0,0 +1,512 @@ +<?php +/** + * Implementation of hook_mail(). + */ +function science_and_concept_map_mail($key, &$message, $params) +{ + global $user; + $language = $message['language']; + //$language = user_preferred_language($user); + switch ($key) + { + case 'science_and_concept_map_proposal_received': + /* initializing data */ + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_proposal'); + $query->condition('id', $params['science_and_concept_map_proposal_received']['result1']); + $query->range(0, 1); + $proposal_data = $query->execute()->fetchObject(); + $user = user_load($params['science_and_concept_map_proposal_received']['user_id']); + if ($proposal_data->project_guide_name == "NULL" || $proposal_data->project_guide_name == "") + { + $project_guide_name = "Not Entered"; + } //$proposal_data->project_guide_name == NULL + else + { + $project_guide_name = $proposal_data->project_guide_name; + } + if ($proposal_data->project_guide_email_id == "NULL" || $proposal_data->project_guide_email_id == "") + { + $project_guide_email_id = "Not Entered"; + } //$proposal_data->project_guide_email_id == NULL + else + { + $project_guide_email_id = $proposal_data->project_guide_email_id; + } + + $message['headers'] = $params['science_and_concept_map_proposal_received']['headers']; + $message['subject'] = t('[!site_name][Science and Concept Map Project] Your soul science and concept map Project proposal has been received', array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +Thank you for submitting the proposal for the SOUL science and concept map Project. The +details of your proposal are as below. + +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 . ' +Title of Category : ' . $proposal_data->category . ' +Project Guide: ' . $project_guide_name . ' +Project Guide Email: ' . $project_guide_email_id . ' +Project Title: ' . $proposal_data->project_title . ' + +Your proposal is under review. You will soon receive an email when the 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 'science_and_concept_map_proposal_disapproved': + /* initializing data */ + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_proposal'); + $query->condition('id', $params['science_and_concept_map_proposal_disapproved']['proposal_id']); + $query->range(0, 1); + $proposal_data = $query->execute()->fetchObject(); + $user_data = user_load($params['science_and_concept_map_proposal_disapproved']['user_id']); + //$user = user_load($params['science_and_concept_map_proposal']['name']); + if ($proposal_data->project_guide_name == "NULL" || $proposal_data->project_guide_name == "") + { + $project_guide_name = "Not Entered"; + } //$proposal_data->project_guide_name == NULL + else + { + $project_guide_name = $proposal_data->project_guide_name; + } + if ($proposal_data->project_guide_email_id == "NULL" || $proposal_data->project_guide_email_id == "") + { + $project_guide_email_id = "Not Entered"; + } //$proposal_data->project_guide_email_id == NULL + else + { + $project_guide_email_id = $proposal_data->project_guide_email_id; + } + $message['headers'] = $params['science_and_concept_map_proposal_disapproved']['headers']; + $message['subject'] = t('[!site_name][Science and Concept Map Project] Your soul science and concept map 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 soul science and concept map Project 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 . ' +Title of Category : ' . $proposal_data->category . ' +Project Guide: ' . $project_guide_name . ' +Project Guide Email: ' . $project_guide_email_id . ' +Project Title: ' . $proposal_data->project_title . ' + +Reason for rejection: ' . $proposal_data->dissapproval_reason . ' + + +Thank you for participating in the SOUL science and concept map Project. 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 'science_and_concept_map_proposal_approved': + /* initializing data */ + $url = 'http://soul.fossee.in/science-and-concept-map-project/abstract-code'; + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_proposal'); + $query->condition('id', $params['science_and_concept_map_proposal_approved']['proposal_id']); + $query->range(0, 1); + $proposal_data = $query->execute()->fetchObject(); + $user_data = user_load($params['science_and_concept_map_proposal_approved']['user_id']); + + if ($proposal_data->project_guide_name == "NULL" || $proposal_data->project_guide_name == "") + { + $project_guide_name = "Not Entered"; + } //$proposal_data->project_guide_name == NULL + else + { + $project_guide_name = $proposal_data->project_guide_name; + } + if ($proposal_data->project_guide_email_id == "NULL" || $proposal_data->project_guide_email_id == "") + { + $project_guide_email_id = "Not Entered"; + } //$proposal_data->project_guide_email_id == NULL + else + { + $project_guide_email_id = $proposal_data->project_guide_email_id; + } + $message['headers'] = $params['science_and_concept_map_proposal_approved']['headers']; + $message['subject'] = t('[!site_name][Science and Concept Map Project] Your soul science and concept map 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 soul science and concept map 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 . ' +Title of Category : ' . $proposal_data->category . ' +Project Guide: ' . $project_guide_name . ' +Project Guide Email: ' . $project_guide_email_id . ' +Project Title: ' . $proposal_data->project_title . ' + +You can upload your report and the 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 'science_and_concept_map_proposal_completed': + /* initializing data */ + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_proposal'); + $query->condition('id', $params['science_and_concept_map_proposal_completed']['proposal_id']); + $query->range(0, 1); + $proposal_data = $query->execute()->fetchObject(); + $user_data = user_load($params['science_and_concept_map_proposal_completed']['user_id']); + if ($proposal_data->project_guide_name == "NULL" || $proposal_data->project_guide_name == "") + { + $project_guide_name = "Not Entered"; + } //$proposal_data->project_guide_name == NULL + else + { + $project_guide_name = $proposal_data->project_guide_name; + } + if ($proposal_data->project_guide_email_id == "NULL" || $proposal_data->project_guide_email_id == "") + { + $project_guide_email_id = "Not Entered"; + } //$proposal_data->project_guide_email_id == NULL + else + { + $project_guide_email_id = $proposal_data->project_guide_email_id; + } + $message['headers'] = $params['science_and_concept_map_proposal_completed']['headers']; + $message['subject'] = t('[!site_name][Science and Concept Map Project] Your soul science and concept map 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 soul science and concept map project on the following process has 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 . ' +Title of Category : ' . $proposal_data->category . ' + +Project Guide: ' . $project_guide_name . ' +Project Guide Email: ' . $project_guide_email_id . ' +Project Title: ' . $proposal_data->project_title . ' + +Kindly access this link to download the same. +https://soul.fossee.in/science-and-concept-map-project/completed-projects + +Thank you for participating in the SOUL science and concept map Project. You are welcome to propose a new science and concept map 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 'science_and_concept_map_proposal_deleted': + /* initializing data */ + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_proposal'); + $query->condition('id', $params['science_and_concept_map_proposal_deleted']['proposal_id']); + $query->range(0, 1); + $proposal_data = $query->execute()->fetchObject(); + $user_data = user_load($params['science_and_concept_map_proposal_deleted']['user_id']); + + if ($proposal_data->project_guide_name == "NULL" || $proposal_data->project_guide_name == "") + { + $project_guide_name = "Not Entered"; + } //$proposal_data->project_guide_name == NULL + else + { + $project_guide_name = $proposal_data->project_guide_name; + } + if ($proposal_data->project_guide_email_id == "NULL" || $proposal_data->project_guide_email_id == "") + { + $project_guide_email_id = "Not Entered"; + } //$proposal_data->project_guide_email_id == NULL + else + { + $project_guide_email_id = $proposal_data->project_guide_email_id; + } + $message['headers'] = $params['science_and_concept_map_proposal_deleted']['headers']; + $message['subject'] = t('[!site_name][Science and Concept Map Project] Your soul science and concept map Project proposal has been deleted', 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 soul science and concept map Project proposal with following details have 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 . ' +Title of Category : ' . $proposal_data->category . ' +Project Guide: ' . $project_guide_name . ' +Project Guide Email: ' . $project_guide_email_id . ' +Project Title: ' . $proposal_data->project_title . ' + +Thank you for participating in the SOUL science and concept map Project. 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 'abstract_uploaded': + // $solution_q = db_query("SELECT * FROM {science_and_concept_map_solution} WHERE id = %d LIMIT 1", $params['abstract_uploaded']['solution_id']); + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_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][Science and Concept Map Project] You have uploaded soul science and concept map 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, + +We received your report and project files for the following details: + +Full Name : ' . $proposal_data->name_title . ' ' . $proposal_data->contributor_name . ' +Project Title : ' . $proposal_data->project_title . ' +Title of Category : ' . $proposal_data->category . ' + +The report 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 'solution_approved': + //$solution_q = db_query("SELECT * FROM {science_and_concept_map_solution} WHERE id = %d LIMIT 1", $params['solution_approved']['solution_id']); + $query = db_select('soul_science_and_concept_map_solution'); + $query->fields('soul_science_and_concept_map_solution'); + $query->condition('id', $params['solution_approved']['solution_id']); + $query->range(0, 1); + $solution_q = $query->execute(); + $solution_data = $solution_q->fetchObject(); + $query = db_select('soul_science_and_concept_map_experiment'); + $query->fields('soul_science_and_concept_map_experiment'); + $query->condition('id', $solution_data->experiment_id); + $query->range(0, 1); + $experiment_q = $query->execute(); + $experiment_data = $experiment_q->fetchObject(); + $user = user_load($params['solution_approved']['user_id']); + $message['headers'] = $params['solution_approved']['headers']; + $message['subject'] = t('[!site_name][Science and Concept Map Project] Your uploaded soul science and concept map solution has been approved', array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +Your following solution has been approved: + +Full Name : ' . $proposal_data->name_title . ' ' . $proposal_data->contributor_name . ' +Project Title : ' . $proposal_data->project_title . ' +Title of Category : ' . $proposal_data->category . ' +Experiment Title : ' . $experiment_data->title . ' +Solution number : ' . $params['solution_disapproved']['solution_number'] . ' +Caption : ' . $params['solution_disapproved']['solution_caption'] . ' + +Please ensure that ALL the codes follow guidelines at https://soul.fossee.in/science-and-concept-map-project/science-and-concept-map-project/submission-guidelines + +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 'solution_disapproved': + $user = user_load($params['solution_disapproved']['user_id']); + $message['headers'] = $params['solution_disapproved']['headers']; + $message['subject'] = t('[!site_name][Science and Concept Map Project] Your uploaded soul science-and-concept-map solution has been disapproved', array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +Your following solution has been disapproved: + +Full Name : ' . $proposal_data->name_title . ' ' . $proposal_data->contributor_name . ' +Project Title: ' . $proposal_data->project_title . ' +Title of Category : ' . $proposal_data->category . ' +Experiment Title : ' . $experiment_data->title . ' +Solution number : ' . $params['solution_disapproved']['solution_number'] . ' +Caption : ' . $params['solution_disapproved']['solution_caption'] . ' + +Reason for dis-approval: ' . $params['solution_disapproved']['message'] . ' + + +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 'solution_deleted_user': + $user = user_load($params['solution_deleted_user']['user_id']); + $message['headers'] = $params['solution_deleted_user']['headers']; + $message['subject'] = t('[!site_name][Science and Concept Map Project] User has deleted the pending soul science-and-concept-map solution', array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +Your following pending solution has been deleted : + +Title of the project : ' . $params['solution_deleted_user']['lab_title'] . ' +Title of Category : ' . $proposal_data->category . ' +Title of the Experiment : ' . $params['solution_deleted_user']['experiment_title'] . ' +Solution number : ' . $params['solution_deleted_user']['solution_number'] . ' +Caption : ' . $params['solution_deleted_user']['solution_caption'] . ' + + +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 'dependency_uploaded': + $user = user_load($params['dependency_uploaded']['user_id']); + $dependency_files = implode(',', $params['dependency_uploaded']['dependency_names']); + $message['headers'] = $params['dependency_uploaded']['headers']; + $message['subject'] = t('[!site_name][Science and Concept Map Project] You have uploaded dependency file', array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +You have uploaded following dependency files : ' . $dependency_files . ' + +Please ensure that ALL the codes follow guidelines at https://soul.fossee.in/soul-science-and-concept-map-project/science-and-concept-map-project/submission-guidelines + +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 +}
\ No newline at end of file diff --git a/full_download.inc b/full_download.inc new file mode 100755 index 0000000..eef1cb0 --- /dev/null +++ b/full_download.inc @@ -0,0 +1,132 @@ +<?php +// $Id$ +function science_and_concept_map_download_full_project() +{ + global $user; + $id = arg(3); + $root_path = science_and_concept_map_path(); + //var_dump($root_path);die; + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_proposal'); + $query->condition('id', $id); + $science_and_concept_map_q = $query->execute(); + $science_and_concept_map_data = $science_and_concept_map_q->fetchObject(); + $SCIENCEANDCONCEPTMAP = $science_and_concept_map_data->directory_name . '/'; + /* 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('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_proposal'); + $query->condition('id', $id); + $science_and_concept_map_udc_q = $query->execute(); + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_proposal'); + $query->condition('id', $id); + $query = db_select('soul_science_and_concept_map_submitted_abstracts_file'); + $query->fields('soul_science_and_concept_map_submitted_abstracts_file'); + $query->condition('proposal_id', $id); + $project_files = $query->execute(); + while ($soul_project_files = $project_files->fetchObject()) { + $zip->addFile($root_path . $SCIENCEANDCONCEPTMAP . 'project_files/' . $soul_project_files->filepath, $SCIENCEANDCONCEPTMAP . str_replace(' ', '_', basename($soul_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(' ', '_', $science_and_concept_map_data->project_title) . '.zip"'); + header('Content-Length: ' . filesize($zip_filename)); + ob_clean(); + readfile($zip_filename); + unlink($zip_filename); + /*flush(); + ob_end_flush(); + ob_clean();*/ + + } //$user->uid + else { + header('Content-Type: application/zip'); + header('Content-disposition: attachment; filename="' . str_replace(' ', '_', $science_and_concept_map_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 science and concept map project in this proposal to download", 'error'); + drupal_goto('science-and-concept-map-project/full-download/project'); + } +} +function science_and_concept_map_download_completed_project() +{ + global $user; + $id = arg(3); + $root_path = science_and_concept_map_path(); + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_proposal'); + $query->condition('id', $id); + $science_and_concept_map_q = $query->execute(); + $science_and_concept_map_data = $science_and_concept_map_q->fetchObject(); + $SCIENCEANDCONCEPTMAP = $science_and_concept_map_data->directory_name . '/'; + /* 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('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_proposal'); + $query->condition('id', $id); + $science_and_concept_map_udc_q = $query->execute(); + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_proposal'); + $query->condition('id', $id); + $query = db_select('soul_science_and_concept_map_submitted_abstracts_file'); + $query->fields('soul_science_and_concept_map_submitted_abstracts_file'); + $query->condition('proposal_id', $id); + $project_files = $query->execute(); + //var_dump($root_path . $SCIENCEANDCONCEPTMAP . 'project_files/');die; + while ($soul_project_files = $project_files->fetchObject()) { + $zip->addFile($root_path . $SCIENCEANDCONCEPTMAP . 'project_files/' . $soul_project_files->filepath, $SCIENCEANDCONCEPTMAP . str_replace(' ', '_', basename($soul_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(' ', '_', $science_and_concept_map_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(' ', '_', $science_and_concept_map_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 science and concept map project in this proposal to download", 'error'); + drupal_goto('science-and-concept-map-project/full-download/project'); + } +}
\ No newline at end of file diff --git a/general_deletion.inc b/general_deletion.inc new file mode 100755 index 0000000..1e555d7 --- /dev/null +++ b/general_deletion.inc @@ -0,0 +1,195 @@ +<?php +/******************************************************************************/ +/****************************** DELETION FUNCTIONS ****************************/ +/******************************************************************************/ +function science_and_concept_map_abstract_delete_project($proposal_id) +{ + $status = TRUE; + $root_path = science_and_concept_map_path(); + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_proposal'); + $query->condition('id', $proposal_id); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + if (!$proposal_data) + { + drupal_set_message('Invalid Flowsheeting Project.', 'error'); + return FALSE; + } //!$proposal_data + $query = db_select('soul_science_and_concept_map_submitted_abstracts_file'); + $query->fields('soul_science_and_concept_map_submitted_abstracts_file'); + $query->condition('proposal_id', $proposal_id); + $abstract_q = $query->execute(); + $dir_project_files = $root_path . $proposal_data->directory_name . '/project_files'; + 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 science and concept map project abstract.', 'error'); + } + db_delete('soul_science_and_concept_map_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'); + $dir_path_udc = $root_path . $proposal_data->directory_name; + if (is_dir($dir_path_udc)) + { + unlink($root_path . $proposal_data->abstractfilepath); + $res = rmdir($dir_path_udc); + } //is_dir($dir_path_udc) + db_delete('soul_science_and_concept_map_proposal')->condition('id', $proposal_data->id)->execute(); + + db_delete('soul_science_and_concept_map_submitted_abstracts')->condition('proposal_id', $proposal_id)->execute(); + return $status; +} +/*function science_and_concept_map_delete_abstract_file($abstract_id) +{ + //var_dump($abstract_id);die; + $status = TRUE; + $root_path = science_and_concept_map_path(); + $abstract_q = db_query("SELECT * from soul_science_and_concept_map_proposal dfp +LEFT JOIN soul_science_and_concept_map_submitted_abstracts dfsa ON dfp.id = dfsa.proposal_id +WHERE dfsa.id = :abstract_id", array( + ":abstract_id" => $abstract_id + )); + $abstract_data = $abstract_q->fetchObject(); + if (!$abstract_data) + { + drupal_set_message('Invalid flowsheet project abstract.', 'error'); + return FALSE; + } //!$abstract_data + /* deleting solutions */ + /*$query = db_select('soul_science_and_concept_map_submitted_abstracts_file'); + $query->fields('soul_science_and_concept_map_submitted_abstracts_file'); + $query->condition('submitted_abstract_id', $abstract_id); + $abstract_f_q = $query->execute(); + $delete_project_folder = FALSE; + while ($abstract_f_data = $abstract_f_q->fetchObject()) + { + $delete_project_folder = TRUE; + if (!_science_and_concept_map_delete_abstract_file($abstract_f_data->id)) + $status = FALSE; + } //$abstract_f_data = $abstract_f_q->fetchObject() + if (!$delete_project_folder) + { + return TRUE; + } //!$delete_project_folder + if ($status) + { + $dir_path_udc = $root_path . $abstract_f_data->directory_name; + if (is_dir($dir_path_udc)) + { + unlink($root_path . $abstract_f_data->abstractfilepath); + //$res = rmdir($dir_path_udc); + /*if (!$res) + { + drupal_set_message(t('Error in deleting user defiend folder !folder', array( + '!folder' => $abstract_f_data->directory_name + )), 'error'); + /* sending email to admins */ + /* $email_to = variable_get('science_and_concept_map_emails', ''); + $from = variable_get('science_and_concept_map_from_email', ''); + $bcc = ""; + $cc = variable_get('science_and_concept_map_cc_emails', ''); + $params['standard']['subject'] = "[ERROR] Error deleting experiment folder"; + $params['standard']['body'] = "Error deleting folder " . $dir_path; + $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('science_and_concept_map', 'standard', $email_to, language_default(), $params, $from, TRUE)) + drupal_set_message('Error sending email message.', 'error'); + return FALSE; + } //!$res + else + { + return TRUE; + } + }*/ //is_dir($dir_path_udc) + /*} //$status + return FALSE; +} +} +function _science_and_concept_map_delete_abstract_file($abstract_id) +{ + global $user; + $root_path = science_and_concept_map_path(); + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_proposal'); + $query->condition('id', $abstract_id); + $abstract_q = $query->execute(); + $abstract_data = $abstract_q->fetchObject(); + $abstract_q = db_query("SELECT * from soul_science_and_concept_map_proposal dfp +LEFT JOIN soul_science_and_concept_map_submitted_abstracts dfsa ON dfp.id = dfsa.proposal_id +WHERE dfsa.id = :abstract_id", array( + ":abstract_id" => $abstract_id + )); + $abstract_data = $abstract_q->fetchObject(); + if (!$abstract_data) + { + drupal_set_message('Invalid flowsheet project abstract.', 'error'); + return FALSE; + } //!$abstract_data + /* deleting abstract files + $query = db_select('soul_science_and_concept_map_submitted_abstracts_file'); + $query->fields('soul_science_and_concept_map_submitted_abstracts_file'); + $query->condition('submitted_abstract_id', $abstract_id); + $abstract_f_q = $query->execute(); + while ($abstract_f_data = $abstract_f_q->fetchObject()) + { + unlink($root_path . $abstract_data->directory_name . '/project_files/' . $abstract_f_data->filepath); + $res = rmdir($root_path . $abstract_data->directory_name . '/project_files'); + /*if (!file_exists($root_path . $abstract_data->directory_name . '/project_files/' . $abstract_f_data->filepath)) + { + $status = FALSE; + drupal_set_message(t('Error deleting !file. File does not exists.', array( + '!file' => $abstract_data->directory_name . '/project_files' . $abstract_f_data->filepath + )), 'error'); + continue; + } //!file_exists($root_path . $abstract_data->directory_name . '/' . $abstract_f_data->filepath) + /* removing solution file */ + /*if (!unlink($root_path . $abstract_data->directory_name . '/project_files/' . $abstract_f_data->filepath)) + { + $status = FALSE; + drupal_set_message(t('Error deleting !file', array( + '!file' => $abstract_data->directory_name . '/project_files/' . $abstract_f_data->filepath + )), 'error'); + /* sending email to admins */ + /* $from = variable_get('science_and_concept_map_from_email', ''); + $bcc = variable_get('science_and_concept_map_emails', ''); + $cc = variable_get('science_and_concept_map_cc_emails', ''); + $params['standard']['subject'] = "[ERROR] Error deleting example file"; + $params['standard']['body'] = "Error deleting solution files by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . " : + file id : " . $abstract_data->id . " + file path : " . $abstract_data->directory_name . '/project_files/' . $abstract_f_data->filepath; + $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('science_and_concept_map', 'standard', $email_to, language_default(), $params, $from, TRUE)) + drupal_set_message('Error sending email message.', 'error'); + } *///!unlink($root_path . $abstract_data->directory_name . '/' . $abstract_f_data->filepath) + +/* } + /* deleting example files database entries */ + //db_delete('soul_science_and_concept_map_submitted_abstracts_file')->condition('id', $abstract_f_data->id)->execute();//$abstract_f_data = $abstract_f_q->fetchObject() +/* if (!$status) + { + return FALSE; + } //!$status + return $status; +}*/
\ No newline at end of file diff --git a/manage_proposal.inc b/manage_proposal.inc new file mode 100755 index 0000000..a0fb54f --- /dev/null +++ b/manage_proposal.inc @@ -0,0 +1,1107 @@ +<?php +// $Id$ +function science_and_concept_map_proposal_pending() +{ + /* get pending proposals to be approved */ + $pending_rows = array(); + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_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', 'science-and-concept-map-project/manage-proposal/approve/' . $pending_data->id) . ' | ' . l('Edit', 'science-and-concept-map-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 science and concept map Project', + 'Action' + ); + //$output = theme_table($pending_header, $pending_rows); + $output = theme('table', array( + 'header' => $pending_header, + 'rows' => $pending_rows + )); + return $output; +} +function science_and_concept_map_proposal_all() +{ + /* get pending proposals to be approved */ + $proposal_rows = array(); + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_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; + 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); + } + $proposal_rows[] = array( + date('d-m-Y', $proposal_data->creation_date), + l($proposal_data->contributor_name, 'user/' . $proposal_data->uid), + $proposal_data->project_title, + $actual_completion_date, + $approval_status, + l('Status', 'science-and-concept-map-project/manage-proposal/status/' . $proposal_data->id) . ' | ' . l('Edit', 'science-and-concept-map-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 science-and-concept-map project', + 'Date of Completion', + 'Status', + 'Action' + ); + $output = theme('table', array( + 'header' => $proposal_header, + 'rows' => $proposal_rows + )); + return $output; +} +/******************************************************************************/ +/************************** PROPOSAL APPROVAL FORM ****************************/ +/******************************************************************************/ +function science_and_concept_map_proposal_approval_form($form, &$form_state) +{ + global $user; + /* get current proposal */ + $proposal_id = (int) arg(3); + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_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('science-and-concept-map-project/manage-proposal'); + return; + } + } //$proposal_q + else + { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('science-and-concept-map-project/manage-proposal'); + return; + } + if ($proposal_data->project_guide_name == "NULL" || $proposal_data->project_guide_name == "") + { + $project_guide_name = "Not Entered"; + } //$proposal_data->project_guide_name == NULL + else + { + $project_guide_name = $proposal_data->project_guide_name; + } + if ($proposal_data->project_guide_email_id == "NULL" || $proposal_data->project_guide_email_id == "") + { + $project_guide_email_id = "Not Entered"; + } //$proposal_data->project_guide_email_id == NULL + else + { + $project_guide_email_id = $proposal_data->project_guide_email_id; + } + $query = db_select('soul_science_and_concept_map_software_version'); + $query->fields('soul_science_and_concept_map_software_version'); + $query->condition('id', $proposal_data->software_version); + $software_version_data = $query->execute()->fetchObject(); + if(!$software_version_data){ + $software_versions = 'NA'; + } + else{ + $software_versions = $software_version_data->software_versions; + } + $form['contributor_name'] = array( + '#type' => 'item', + '#markup' => l($proposal_data->name_title . ' ' . $proposal_data->contributor_name, 'user/' . $proposal_data->uid), + '#title' => t('Contributor 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['month_year_of_degree'] = array( + '#type' => 'date_popup', + '#title' => t('Month and year of award of degree'), + '#date_label_position' => '', + '#description' => '', + '#default_value' => $proposal_data->month_year_of_degree, + '#date_format' => 'd-M-Y', + '#date_increment' => 0, + '#date_year_range' => '1960:+0', + '#datepicker_options' => array( + 'maxDate' => 0 + ), + '#disabled' => TRUE + ); + $form['university'] = array( + '#type' => 'item', + '#markup' => $proposal_data->university, + '#title' => t('University/Institute') + ); + $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['category'] = array( + '#type' => 'item', + '#markup' => $proposal_data->category, + '#title' => t('Category') + ); + $form['sub_category'] = array( + '#type' => 'item', + '#markup' => $proposal_data->sub_category, + '#title' => t('Sub Category') + ); + $form['software_version'] = array( + '#type' => 'item', + '#markup' => $software_versions, + '#title' => t('Software Version') + ); + $form['software_version_no'] = array( + '#type' => 'item', + '#markup' => $proposal_data->software_version_no, + '#title' => t('Software Version No') + ); + $form['other_software_version_no'] = array( + '#type' => 'item', + '#markup' => $proposal_data->other_software_version_no, + '#title' => t('Other Software Version No') + ); + $form['project_guide_name'] = array( + '#type' => 'item', + '#title' => t('Project guide'), + '#markup' => $project_guide_name + ); + $form['project_guide_email_id'] = array( + '#type' => 'item', + '#title' => t('Project guide email'), + '#markup' => $project_guide_email_id + ); + $form['project_title'] = array( + '#type' => 'item', + '#markup' => $proposal_data->project_title, + '#title' => t('Title of the science and concept map Project') + ); + $form['description'] = array( + '#type' => 'item', + '#markup' => $proposal_data->description, + '#title' => t('Description of the science and concept map Project') + ); + if (($proposal_data->abstractfilepath != "") && ($proposal_data->abstractfilepath != 'NULL')) + { + $str = substr($proposal_data->abstractfilepath,strrpos($proposal_data->abstractfilepath, '/')); + $resource_file =ltrim($str, '/'); + + $form['abstractfilepath'] = array( + '#type' => 'item', + '#title' => t('Abstract file '), + '#markup' => l($resource_file, 'science-and-concept-map-project/download/abstract-file/' . $proposal_id) . "" + ); + } //$proposal_data->user_defined_compound_filepath != "" + else + { + $form['abstractfilepath'] = array( + '#type' => 'item', + '#title' => t('Abstract file '), + '#markup' => "Not uploaded<br><br>" + ); + } + $form['approval'] = array( + '#type' => 'radios', + '#title' => t('soul science-and-concept-map 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'), 'science-and-concept-map-project/manage-proposal') + ); + return $form; +} +function science_and_concept_map_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 science_and_concept_map_proposal_approval_form_submit($form, &$form_state) +{ + global $user; + /* get current proposal */ + $proposal_id = (int) arg(3); + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_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('science-and-concept-map-project/manage-proposal'); + return; + } + } //$proposal_q + else + { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('science-and-concept-map-project/manage-proposal'); + return; + } + if ($form_state['values']['approval'] == 1) + { + $query = "UPDATE {soul_science_and_concept_map_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('science_and_concept_map_from_email', ''); + $bcc = $user->mail . ', ' . variable_get('science_and_concept_map_emails', ''); + $cc = variable_get('science_and_concept_map_cc_emails', ''); + $params['science_and_concept_map_proposal_approved']['proposal_id'] = $proposal_id; + $params['science_and_concept_map_proposal_approved']['user_id'] = $proposal_data->uid; + $params['science_and_concept_map_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('science_and_concept_map', 'science_and_concept_map_proposal_approved', $email_to, language_default(), $params, $from, TRUE)) + drupal_set_message('Error sending email message.', 'error'); + drupal_set_message('soul science-and-concept-map proposal No. ' . $proposal_id . ' approved. User has been notified of the approval.', 'status'); + drupal_goto('science-and-concept-map-project/manage-proposal'); + return; + } //$form_state['values']['approval'] == 1 + else if ($form_state['values']['approval'] == 2) + { + $query = "UPDATE {soul_science_and_concept_map_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('science_and_concept_map_from_email', ''); + $bcc = $user->mail . ', ' . variable_get('science_and_concept_map_emails', ''); + $cc = variable_get('science_and_concept_map_cc_emails', ''); + $params['science_and_concept_map_proposal_disapproved']['proposal_id'] = $proposal_id; + $params['science_and_concept_map_proposal_disapproved']['user_id'] = $proposal_data->uid; + $params['science_and_concept_map_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('science_and_concept_map', 'science_and_concept_map_proposal_disapproved', $email_to, language_default(), $params, $from, TRUE)) + drupal_set_message('Error sending email message.', 'error'); + drupal_set_message('soul science and concept map proposal No. ' . $proposal_id . ' dis-approved. User has been notified of the dis-approval.', 'error'); + drupal_goto('science-and-concept-map-project/manage-proposal'); + return; + } //$form_state['values']['approval'] == 2 +} +/******************************************************************************/ +/*************************** PROPOSAL STATUS FORM *****************************/ +/******************************************************************************/ +function science_and_concept_map_proposal_status_form($form, &$form_state) +{ + global $user; + /* get current proposal */ + $proposal_id = (int) arg(3); + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_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('science-and-concept-map-project/manage-proposal'); + return; + } + } //$proposal_q + else + { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('science-and-concept-map-project/manage-proposal'); + return; + } + if ($proposal_data->country == "NULL" || $proposal_data->country == "") + { + $country = "Not Entered"; + } //$proposal_data->country == NULL + else + { + $country = $proposal_data->country; + } + if ($proposal_data->state == "NULL" || $proposal_data->state == "") + { + $state = "Not Entered"; + } //$proposal_data->state == NULL + else + { + $state = $proposal_data->state; + } + if ($proposal_data->city == "NULL" || $proposal_data->city == "") + { + $city = "Not Entered"; + } //$proposal_data->city == NULL + else + { + $city = $proposal_data->city; + } + if ($proposal_data->project_guide_name == "NULL" || $proposal_data->project_guide_name == "") + { + $project_guide_name = "Not Entered"; + } //$proposal_data->project_guide_name == NULL + else + { + $project_guide_name = $proposal_data->project_guide_name; + } + if ($proposal_data->project_guide_email_id == "NULL" || $proposal_data->project_guide_email_id == "") + { + $project_guide_email_id = "Not Entered"; + } //$proposal_data->project_guide_email_id == NULL + else + { + $project_guide_email_id = $proposal_data->project_guide_email_id; + } + $query = db_select('soul_science_and_concept_map_software_version'); + $query->fields('soul_science_and_concept_map_software_version'); + $query->condition('id', $proposal_data->software_version); + $software_version_data = $query->execute()->fetchObject(); + if(!$software_version_data){ + $software_versions = 'NA'; + } + else{ + $software_versions = $software_version_data->software_versions; + } + + $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['month_year_of_degree'] = array( + '#type' => 'date_popup', + '#title' => t('Month and year of award of degree'), + '#date_label_position' => '', + '#description' => '', + '#default_value' => $proposal_data->month_year_of_degree, + '#date_format' => 'M-Y', + '#date_increment' => 0, + '#date_year_range' => '1960:+0', + '#datepicker_options' => array( + 'maxDate' => 0 + ), + '#disabled' => TRUE + );*/ + $form['university'] = array( + '#type' => 'item', + '#markup' => $proposal_data->university, + '#title' => t('University/Institute') + ); + $form['country'] = array( + '#type' => 'item', + '#markup' => $country, + '#title' => t('Country') + ); + $form['state'] = array( + '#type' => 'item', + '#markup' => $state, + '#title' => t('State') + ); + $form['city'] = array( + '#type' => 'item', + '#markup' => $city, + '#title' => t('City') + ); + $form['pincode'] = array( + '#type' => 'item', + '#markup' => $proposal_data->pincode, + '#title' => t('Pincode/Postal code') + ); + $form['project_guide_name'] = array( + '#type' => 'item', + '#title' => t('Project guide'), + '#markup' => $project_guide_name + ); + $form['project_guide_email_id'] = array( + '#type' => 'item', + '#title' => t('Project guide email'), + '#markup' => $project_guide_email_id + ); + $form['category'] = array( + '#type' => 'item', + '#markup' => $proposal_data->category, + '#title' => t('Category') + ); + $form['sub_category'] = array( + '#type' => 'item', + '#markup' => $proposal_data->sub_category, + '#title' => t('Sub Category') + ); + $form['software_version'] = array( + '#type' => 'item', + '#markup' => $software_versions, + '#title' => t('Software Version') + ); + $form['software_version_no'] = array( + '#type' => 'item', + '#markup' => $proposal_data->software_version_no, + '#title' => t('Software Version No') + ); + $form['other_software_version_no'] = array( + '#type' => 'item', + '#markup' => $proposal_data->other_software_version_no, + '#title' => t('Other Software Version No') + ); + $form['project_title'] = array( + '#type' => 'item', + '#markup' => $proposal_data->project_title, + '#title' => t('Title of the science and concept map Project') + ); + /************************** reference link filter *******************/ + $url = '~(?:(https?)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+))(?<![\.,:])~i'; + $reference = preg_replace($url, '<a href="$0" target="_blank" title="$0">$0</a>', $proposal_data->reference); + /******************************/ + $form['reference'] = array( + '#type' => 'item', + '#markup' => $reference, + '#title' => t('References') + ); + $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; + 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', 'science-and-concept-map-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'), 'science-and-concept-map-project/manage-proposal/all') + ); + return $form; +} +function science_and_concept_map_proposal_status_form_submit($form, &$form_state) +{ + global $user; + /* get current proposal */ + $proposal_id = (int) arg(3); + //$proposal_q = db_query("SELECT * FROM {soul_science_and_concept_map_proposal} WHERE id = %d", $proposal_id); + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_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('science-and-concept-map-project/manage-proposal'); + return; + } + } //$proposal_q + else + { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('science-and-concept-map-project/manage-proposal'); + return; + } + /* set the book status to completed */ + if ($form_state['values']['completed'] == 1) + { + $up_query = "UPDATE soul_science_and_concept_map_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); + CreateReadmeFileSoulScienceAndConceptMapProject($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('science_and_concept_map_from_email', ''); + $bcc = $user->mail . ', ' . variable_get('science_and_concept_map_emails', ''); + $cc = variable_get('science_and_concept_map_cc_emails', ''); + $params['science_and_concept_map_proposal_completed']['proposal_id'] = $proposal_id; + $params['science_and_concept_map_proposal_completed']['user_id'] = $proposal_data->uid; + $params['science_and_concept_map_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('science_and_concept_map', 'science_and_concept_map_proposal_completed', $email_to, language_default(), $params, $from, TRUE)) + drupal_set_message('Error sending email message.', 'error'); + drupal_set_message('Congratulations! soul science and concept map proposal has been marked as completed. User has been notified of the completion.', 'status'); + } + drupal_goto('science-and-concept-map-project/manage-proposal'); + return; + +} +/******************************************************************************/ +/**************************** PROPOSAL EDIT FORM ******************************/ +/******************************************************************************/ +function science_and_concept_map_proposal_edit_form($form, &$form_state) +{ + global $user; + /* get current proposal */ + $proposal_id = (int) arg(3); + //$proposal_q = db_query("SELECT * FROM {soul_science_and_concept_map_proposal} WHERE id = %d", $proposal_id); + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_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('science-and-concept-map-project/manage-proposal'); + return; + } + } //$proposal_q + else + { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('science-and-concept-map-project/manage-proposal'); + return; + } + $query = db_select('soul_science_and_concept_map_software_version'); + $query->fields('soul_science_and_concept_map_software_version'); + $query->condition('id', $proposal_data->software_version); + $software_version_data = $query->execute()->fetchObject(); + if(!$software_version_data){ + $software_versions = 'NA'; + } + else{ + $software_versions = $software_version_data->software_versions; + } + $user_data = user_load($proposal_data->uid); + $form['name_title'] = array( + '#type' => 'select', + '#title' => t('Title'), + '#options' => array( + 'Dr' => 'Dr', + 'Prof' => 'Prof', + 'Mr' => 'Mr', + 'Mrs' => 'Mrs', + '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['month_year_of_degree'] = array( + '#type' => 'date_popup', + '#title' => t('Month and year of award of degree'), + '#date_label_position' => '', + '#description' => '', + '#default_value' => $proposal_data->month_year_of_degree, + '#date_format' => 'M-Y', + '#date_increment' => 0, + '#date_year_range' => '1960:+0', + '#datepicker_options' => array( + 'maxDate' => 0 + ), + '#disabled' => TRUE + ); + $form['university'] = array( + '#type' => 'textfield', + '#title' => t('University/Institute'), + '#size' => 200, + '#maxlength' => 200, + '#required' => TRUE, + '#default_value' => $proposal_data->university + ); + $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['category'] = array( + '#type' => 'item', + '#markup' => $proposal_data->category, + '#title' => t('Category') + ); + $form['sub_category'] = array( + '#type' => 'item', + '#markup' => $proposal_data->sub_category, + '#title' => t('Sub Category') + ); + $form['software_version'] = array( + '#type' => 'item', + '#markup' => $software_versions, + '#title' => t('Software Version') + ); + $form['software_version_no'] = array( + '#type' => 'item', + '#markup' => $proposal_data->software_version_no, + '#title' => t('Software Version No') + ); + $form['other_software_version_no'] = array( + '#type' => 'item', + '#markup' => $proposal_data->other_software_version_no, + '#title' => t('Other Software Version No') + ); + $form['project_title'] = array( + '#type' => 'textarea', + '#title' => t('Title of the science and concept map Project'), + '#size' => 300, + '#maxlength' => 350, + '#required' => TRUE, + '#default_value' => $proposal_data->project_title + ); + $form['reference'] = array( + '#type' => 'textarea', + '#title' => t('Reference'), + '#size' => 10000, + '#attributes' => array( + 'placeholder' => 'Links of must be provided....' + ), + '#default_value' => $proposal_data->reference + ); + $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'), 'science-and-concept-map-project/manage-proposal') + ); + return $form; +} + +function science_and_concept_map_proposal_edit_form_validate($form, &$form_state) +{ + //Validation for project title + $form_state['values']['project_title'] = trim($form_state['values']['project_title']); + if ($form_state['values']['project_title'] != '') + { + if (strlen($form_state['values']['project_title']) > 250) + { + form_set_error('project_title', t('Maximum charater limit is 250 charaters only, please check the length of the project title')); + } //strlen($form_state['values']['project_title']) > 250 + else if (strlen($form_state['values']['project_title']) < 10) + { + form_set_error('project_title', t('Minimum charater limit is 10 charaters, please check the length of the project title')); + } //strlen($form_state['values']['project_title']) < 10 + } //$form_state['values']['project_title'] != '' + else + { + form_set_error('project_title', t('Project title shoud not be empty')); + } + if(preg_match('/[\^£$%&*()}{@#~?><>.:;`|=+¬]/', $form_state['values']['project_title'])) + { + form_set_error('project_title', t('Special characters are not allowed for Project Title')); + } + return $form_state; +} + + +function science_and_concept_map_proposal_edit_form_submit($form, &$form_state) +{ + global $user; + /* get current proposal */ + $proposal_id = (int) arg(3); + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_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('science-and-concept-map-project/manage-proposal'); + return; + } + } //$proposal_q + else + { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('science-and-concept-map-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('science_and_concept_map_from_email', ''); + $bcc = variable_get('science_and_concept_map_emails', ''); + $cc = variable_get('science_and_concept_map_cc_emails', ''); + $params['science_and_concept_map_proposal_deleted']['proposal_id'] = $proposal_id; + $params['science_and_concept_map_proposal_deleted']['user_id'] = $proposal_data->uid; + $params['science_and_concept_map_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('science_and_concept_map', 'science_and_concept_map_proposal_deleted', $email_to, user_preferred_language($user), $params, $from, TRUE)) + drupal_set_message('Error sending email message.', 'error'); + drupal_set_message(t('soul science-and-concept-map-project proposal has been deleted.'), 'status'); + if (rrmdir_project($proposal_id) == TRUE) + { + $query = db_delete('soul_science_and_concept_map_proposal'); + $query->condition('id', $proposal_id); + $num_deleted = $query->execute(); + drupal_set_message(t('Proposal Deleted'), 'status'); + drupal_goto('science-and-concept-map-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; + } + $str = substr($proposal_data->abstractfilepath,strrpos($proposal_data->abstractfilepath, '/')); + $resource_file =ltrim($str, '/'); + $abstractfilepath = $directory_name . '/' . $resource_file; + $query = "UPDATE soul_science_and_concept_map_proposal SET + name_title=:name_title, + contributor_name=:contributor_name, + university=:university, + city=:city, + pincode=:pincode, + state=:state, + project_title=:project_title, + reference=:reference, + directory_name=:directory_name , + abstractfilepath=:abstractfilepath + WHERE id=:proposal_id"; + $args = array( + ':name_title' => $v['name_title'], + ':contributor_name' => $v['contributor_name'], + ':university' => $v['university'], + ':city' => $v['city'], + ':pincode' => $v['pincode'], + ':state' => $v['all_state'], + ':project_title' => $project_title, + ':reference' => $v['reference'], + ':directory_name' => $directory_name, + ':abstractfilepath' => $abstractfilepath, + ':proposal_id' => $proposal_id + ); + $result = db_query($query, $args); + drupal_set_message(t('Proposal Updated'), 'status'); +}
\ No newline at end of file diff --git a/proposal.inc b/proposal.inc new file mode 100755 index 0000000..3b6b1f6 --- /dev/null +++ b/proposal.inc @@ -0,0 +1,765 @@ +<?php +// $Id$ +/* +Approval Status : +0 - Pending +1 - Approved +2 - Dis-Approved +3 - Completed +Solution Status : +0 - Pending +1 - Approved +2 - Dis-Approved +Solution Display : +0 - No +1 - Yes + + +is_completed +0 - in progress +1 - Completed +Tables : +science_and_concept_map_solution : approval_status +0 - Pending +1 - Approved +2 - Disapproved (delete it) +*/ +function science_and_concept_map_proposal_form($form, &$form_state, $no_js_use = FALSE) +{ + global $user; + /************************ start approve book details ************************/ + if ($user->uid == 0) + { + $msg = drupal_set_message(t('It is mandatory to ' . l('login', 'user') . ' on this website to access the science and concept map proposal form. If you are new user please create a new account first.'), 'error'); + //drupal_goto('soul-science-and-concept-map-project'); + drupal_goto('user/login', array('query' => drupal_get_destination())); + return $msg; + } //$user->uid == 0 + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_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', + 'Mrs' => 'Mrs', + '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('School/Institute/University/Organisation'), + '#size' => 80, + '#maxlength' => 200, + '#attributes' => array( + 'placeholder' => 'Enter full name of your School/Institute/University/Organisation.... ' + ), + '#required' => TRUE + ); + $form['department'] = array( + '#type' => 'textfield', + '#title' => t('Department/Branch'), + '#size' => 80, + '#maxlength' => 200, + '#attributes' => array( + 'placeholder' => 'Enter Department/Branch.... ' + ) + ); + $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' => _df_list_of_states(), + '#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(), + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array( + 'value' => 'India' + ) + ) + ) + ); + $form['pincode'] = array( + '#type' => 'textfield', + '#title' => t('Pincode'), + '#attributes' => array( + 'placeholder' => t('Enter Pincode') + ), + '#size' => 6 + ); + /***************************************************************************/ + $form['hr'] = array( + '#type' => 'item', + '#markup' => '<hr>' + ); + $form['project_guide_name'] = array( + '#type' => 'textfield', + '#title' => t('Name of the faculty member of your Institution, if any, who helped you with this project '), + '#size' => 250, + '#attributes' => array( + 'placeholder' => t('Enter full name of faculty member') + ), + '#maxlength' => 250 + ); + $form['project_guide_department'] = array( + '#type' => 'textfield', + '#title' => t('Department of the faculty member of your Institution, if any, who helped you with this project '), + '#size' => 250, + '#attributes' => array( + 'placeholder' => t('Enter department name of faculty member') + ), + '#maxlength' => 250 + ); + $form['project_guide_email_id'] = array( + '#type' => 'textfield', + '#title' => t('Email id of the faculty member of your Institution, if any, who helped you with this project'), + '#size' => 30, + '#attributes' => array( + 'placeholder' => t('Enter Email id of the faculty member') + ), + ); + $form['options'] = array( + '#type' => 'select', + '#title' => t('How did you come to know about the science and concept map project'), + '#options' => array( + 'Poster' => 'Poster', + 'Website' => 'Website', + 'Email' => 'Email', + 'Workshop' => 'Workshop', + 'others' => 'others' + ), + '#required' => TRUE, + '#tree' => TRUE, + '#validated' => TRUE + ); + $form['category'] = array( + '#type' => 'select', + '#title' => t('Select Category'), + '#options' => _soul_list_of_category(), + '#required' => TRUE, + '#tree' => TRUE, + '#validated' => TRUE + ); + $form['sub_category'] = array( + '#type' => 'select', + '#title' => t('Select Sub Category for 3D Modeling Project'), + '#options' => _soul_list_of_sub_category(), + '#default_value' => none, + '#states' => array( + 'visible' => array( + ':input[name="category"]' => array( + 'value' => '3D Modeling Project' + ) + ) + ) + ); + $software_version_options = _soul_list_of_software_version(); + $form['software_version'] = array( + '#type' => 'select', + '#title' => t('Select Software Version'), + '#options' => $software_version_options, + '#required' => TRUE, + '#ajax' => array( + 'callback' => 'ajax_solver_used_callback', + ), + ); + $software_version_id = isset($form_state['values']['software_version']) ? $form_state['values']['software_version'] : key($software_version_options); + $form['software_version_no'] = array( + '#type' => 'select', + '#title' => t('Select the Software Version Number to be used'), + '#options' => _soul_list_of_software_version_details($software_version_id), + '#default_value' => 0, + '#prefix' => '<div id="ajax-solver-replace">', + '#suffix' => '</div>', + '#required' => TRUE, + '#tree' => TRUE, + '#validated' => TRUE + ); + $form['other_software_version_no'] = array( + '#type' => 'textfield', + '#title' => t('Enter your answer'), + '#size' => 100, + '#attributes' => array( + 'placeholder' => t('Enter your answer') + ), + '#states' => array( + 'visible' => array( + ':input[name="software_version_no"]' => array( + 'value' => 'Another' + ) + ) + ) + ); + + $form['project_title'] = array( + '#type' => 'textarea', + '#title' => t('Project Title'), + '#size' => 250, + '#description' => t('Minimum character limit is 10 and Maximum character limit is 250'), + '#attributes' => array( + 'placeholder' => t('Enter Project Title') + ), + '#required' => TRUE + ); + $form['description'] = array( + '#type' => 'textarea', + '#title' => t('Project Description'), + '#size' => 250, + '#attributes' => array( + 'placeholder' => t('Enter Project Description') + ), + '#description' => t('Minimum character limit is 250 and Maximum character limit is 700'), + '#required' => TRUE + ); + $form['samplefile'] = array( + '#type' => 'fieldset', + '#title' => t('Submit an abstract<span style="color:red">*</span>'), + '#collapsible' => FALSE, + '#collapsed' => FALSE + ); + $form['samplefile']['abstractfilepath'] = array( + '#type' => 'file', + //'#title' => t('Upload circuit diagram'), + '#size' => 48, + '#description' => t('Upload filenames with allowed extensions only. No spaces or any special characters allowed in filename.') . '<br />' . t('<span style="color:red;">Allowed file extensions : ') . variable_get('science_and_concept_map_abstract_upload_extensions', '') . '</span>' + ); + $form['reference'] = array( + '#type' => 'textfield', + '#description' => t('The links to the documents or websites which are referenced while proposing this project.'), + '#title' => t('Reference'), + '#size' => 250, + '#required' => TRUE, + + '#attributes' => array( + 'placeholder' => 'Enter reference' + ) + + ); + /*$form['fellowship'] = array( + '#type' => 'radios', + '#title' => t('If you are applying for FOSSEE Summer Fellowship 2018 - soul Screening level Task 1, select Yes.(To know more about the FOSSEE Summer Fellowship 2018 <a href="https://fossee.in/fellowship/" target="_blank">Click here</a>)'), + '#options' => array( + '1' => 'Yes', + '2' => 'No' + ), + '#required' => TRUE + );*/ + + $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', + '#datepicker_options' => array('maxDate' => 31, 'minDate' => 0), + '#required' => TRUE + ); + + $form['term_condition'] = array( + '#type' => 'checkboxes', + '#title' => t('Terms And Conditions'), + '#options' => array( + 'status' => t('<a href="term-and-conditions" target="_blank">I agree to the Terms and Conditions</a>') + ), + '#required' => TRUE + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); + return $form; +} + +function ajax_solver_used_callback($form, $form_state) +{ + $commands = array(); + $software_version_id = isset($form_state['values']['software_version']) ? $form_state['values']['software_version'] : key($software_version_options); + if($software_version_id != 7){ + $form['software_version_no']['#options'] = _soul_list_of_software_version_details($software_version_id);/* + $form['software_version_no']['#required'] = TRUE; + $form['software_version_no']['#validated'] = TRUE;*/ + $commands[] = ajax_command_replace('#ajax-solver-replace', drupal_render($form['software_version_no'])); + $commands[] = ajax_command_html('#ajax-solver-text-replace', ''); + } + else{ + $commands[] = ajax_command_html('#ajax-solver-replace', ''); + $commands[] = ajax_command_html('#ajax-solver-text-replace', drupal_render($form['other_software_version_no'])); + } + return array( + '#type' => 'ajax', + '#commands' => $commands + ); +} +function science_and_concept_map_proposal_form_validate($form, &$form_state) +{ + if(preg_match('/[\^£$%&*()}{@#~?><>.:;`|=_+¬]/', $form_state['values']['contributor_name'])) + { + form_set_error('contributor_name', t('Special characters are not allowed for Contributor Name')); + } + if (!preg_match('/^[0-9\ \+]{0,15}$/', $form_state['values']['contributor_contact_no'])) + { + form_set_error('contributor_contact_no', t('Invalid contact phone number')); + } + 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 + $form_state['values']['project_title'] = trim($form_state['values']['project_title']); + if ($form_state['values']['project_title'] != '') + { + if (strlen($form_state['values']['project_title']) > 250) + { + form_set_error('project_title', t('Maximum charater limit is 250 charaters only, please check the length of the project title')); + } //strlen($form_state['values']['project_title']) > 250 + else if (strlen($form_state['values']['project_title']) < 10) + { + form_set_error('project_title', t('Minimum charater limit is 10 charaters, please check the length of the project title')); + } //strlen($form_state['values']['project_title']) < 10 + } //$form_state['values']['project_title'] != '' + else + { + form_set_error('project_title', t('Project title shoud not be empty')); + } + if(preg_match('/[\^£$%&*()}{@#~?><>.:;`|=+¬]/', $form_state['values']['project_title'])) + { + form_set_error('project_title', t('Special characters are not allowed for Project Title')); + } + $form_state['values']['description'] = trim($form_state['values']['description']); + if ($form_state['values']['description'] != '') + { + if (strlen($form_state['values']['description']) > 700) + { + form_set_error('description', t('Maximum charater limit is 700 charaters only, please check the length of the description')); + } //strlen($form_state['values']['project_title']) > 250 + else if (strlen($form_state['values']['description']) < 250) + { + form_set_error('description', t('Minimum charater limit is 250 charaters, please check the length of the description')); + } //strlen($form_state['values']['project_title']) < 10 + } //$form_state['values']['project_title'] != '' + else + { + form_set_error('description', t('Description shoud not be empty')); + } +if (isset($_FILES['files'])) + { + /* check if atleast one source or result file is uploaded */ + if (!($_FILES['files']['name']['abstractfilepath'])) + form_set_error('abstractfilepath', t('Please upload Abstract file.')); + /* check for valid filename extensions */ + foreach ($_FILES['files']['name'] as $file_form_name => $file_name) + { + if ($file_name) + { + /* checking file type */ + /*if (strstr($file_form_name, 'sample')) + $file_type = 'S'; + else + $file_type = 'U'; + + /*switch ($file_type) + { + case 'S': + $allowed_extensions_str = variable_get('textbook_companion_source_extensions', ''); + break; + } *///$file_type + $allowed_extensions_str = variable_get('science_and_concept_map_abstract_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 (!textbook_companion_check_valid_filename($_FILES['files']['name'][$file_form_name])) + form_set_error($file_form_name, t('Invalid file name specified. Only alphabets and numbers are allowed as a valid filename.'));*/ + } //$file_name + } //$_FILES['files']['name'] as $file_form_name => $file_name + } + return $form_state; +} +function science_and_concept_map_proposal_form_submit($form, &$form_state) +{ + global $user; + $root_path = science_and_concept_map_path(); + if (!$user->uid) + { + drupal_set_message('It is mandatory to login on this website to access the proposal form', 'error'); + return; + } //!$user->uid + /* 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']; + $department = $v['department']; + $options = $v['options']; + $category = $v['category']; + $software_version_no =$v['software_version_no']; + $month_year_of_degree = $v['month_year_of_degree']; + $directory_name = _df_dir_name($project_title, $proposar_name); + if ($category == '3D Modeling Project') + { + $sub_category = $v['sub_category']; + } + else + { + $sub_category = 'None'; + } + + if ($software_version_no == 'Another') + { + $other_software_version_no = $v['other_software_version_no']; + } + else + { + $other_software_version_no = 'None'; + } + + + $result = "INSERT INTO {soul_science_and_concept_map_proposal} + ( + uid, + approver_uid, + name_title, + contributor_name, + contact_no, + university, + department, + city, + state, + country, + pincode, + project_guide_name, + project_guide_department, + project_guide_email_id, + options, + category, + sub_category, + project_title, + description, + software_version, + software_version_no, + other_software_version_no, + directory_name, + approval_status, + is_completed, + dissapproval_reason, + creation_date, + approval_date, + abstractfilepath, + reference, + expected_date_of_completion + ) VALUES + ( + :uid, + :approver_uid, + :name_title, + :contributor_name, + :contact_no, + :university, + :department, + :city, + :state, + :country, + :pincode, + :project_guide_name, + :project_guide_department, + :project_guide_email_id, + :options, + :category, + :sub_category, + :project_title, + :description, + :software_version, + :software_version_no, + :other_software_version_no, + :directory_name, + :approval_status, + :is_completed, + :dissapproval_reason, + :creation_date, + :approval_date, + :abstractfilepath, + :reference, + :expected_date_of_completion + )"; + $args = array( + ":uid" => $user->uid, + ":approver_uid" => 0, + ":name_title" => $v['name_title'], + ":contributor_name" => _df_sentence_case(trim($v['contributor_name'])), + ":contact_no" => $v['contributor_contact_no'], + ":university" => _df_sentence_case($v['university']), + ":department" => $v['department'], + ":city" => $v['city'], + ":pincode" => $v['pincode'], + ":state" => $v['all_state'], + ":country" => $v['country'], + ":project_guide_name" => _df_sentence_case($v['project_guide_name']), + ":project_guide_department" =>trim($v['project_guide_department']), + ":project_guide_email_id" => trim($v['project_guide_email_id']), + ":options" =>$v['options'], + ":category" => $category, + ":sub_category" => $sub_category, + ":project_title" => _df_sentence_case($v['project_title']), + ":description" => _df_sentence_case($v['description']), + ":software_version" =>$v['software_version'], + ":software_version_no" =>$software_version_no, + ":other_software_version_no" => $other_software_version_no, + ":directory_name" => $directory_name, + ":approval_status" => 0, + ":is_completed" => 0, + ":dissapproval_reason" => "NULL", + ":creation_date" => time(), + ":approval_date" => 0, + ":expected_date_of_completion" => strtotime(date($v['expected_date_of_completion'])), + ":abstractfilepath" => "", + ":reference" => $v['reference'] + ); + //var_dump($args);die; + //var_dump($result);die; + $result1 = db_query($result, $args, array( + 'return' => Database::RETURN_INSERT_ID + )); +//var_dump($args);die; + + $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 {soul_science_and_concept_map_proposal} SET abstractfilepath = :abstractfilepath WHERE id = :id"; + $args = array( + ":abstractfilepath" => $dest_path . $_FILES['files']['name'][$file_form_name], + ":id" => $result1 + ); + + $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 (!$result1) + { + drupal_set_message(t('Error receiving your proposal. Please try again.'), 'error'); + return; + } //!$proposal_id + /* sending email */ + $email_to = $user->mail; + $form = variable_get('science_and_concept_map_from_email', ''); + $bcc = variable_get('science_and_concept_map_emails', ''); + $cc = variable_get('science_and_concept_map_cc_emails', ''); + $params['science_and_concept_map_proposal_received']['result1'] = $result1; + $params['science_and_concept_map_proposal_received']['user_id'] = $user->uid; + $params['science_and_concept_map_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('science_and_concept_map', 'science_and_concept_map_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 soul science and concept map proposal. We will get back to you soon.'), 'status'); + drupal_goto(''); +} @@ -0,0 +1,150 @@ +<?php +function science_and_concept_map_run_form($form, &$form_state) +{ + $options_first = _list_of_science_and_concept_map(); + $url_science_and_concept_map_id = (int) arg(2); + $science_and_concept_map_data = _science_and_concept_map_information($url_science_and_concept_map_id); + if ($science_and_concept_map_data == 'Not found') { + $url_science_and_concept_map_id = ''; + } //$science_and_concept_map_data == 'Not found' + if (!$url_science_and_concept_map_id) { + $selected = isset($form_state['values']['science_and_concept_map']) ? $form_state['values']['science_and_concept_map'] : key($options_first); + } //!$url_science_and_concept_map_id + elseif ($url_science_and_concept_map_id == '') { + $selected = 0; + } //$url_science_and_concept_map_id == '' + else { + $selected = $url_science_and_concept_map_id; + } + $form = array(); + $form['science_and_concept_map'] = array( + '#type' => 'select', + '#title' => t('Title of the science and concept map'), + '#options' => _list_of_science_and_concept_map(), + '#default_value' => $selected, + '#ajax' => array( + 'callback' => 'science_and_concept_map_project_details_callback' + ) + ); + if (!$url_science_and_concept_map_id) { + $form['science_and_concept_map_details'] = array( + '#type' => 'item', + '#markup' => '<div id="ajax_science_and_concept_map_details"></div>' + ); + $form['selected_science_and_concept_map'] = array( + '#type' => 'item', + '#markup' => '<div id="ajax_selected_science_and_concept_map"></div>' + ); + } //!$url_science_and_concept_map_id + else { + $science_and_concept_map_default_value = $url_science_and_concept_map_id; + $form['science_and_concept_map_details'] = array( + '#type' => 'item', + '#markup' => '<div id="ajax_science_and_concept_map_details">' . _science_and_concept_map_details($science_and_concept_map_default_value) . '</div>' + ); + $form['selected_science_and_concept_map'] = array( + '#type' => 'item', + '#markup' => '<div id="ajax_selected_science_and_concept_map">' . l('Download Abstract', "science-and-concept-map-project/download/abstract-file/" . $science_and_concept_map_default_value) . '<br>' . l('Download science and concept map', 'science-and-concept-map-project/full-download/project/' . $science_and_concept_map_default_value) . '</div>' + ); + } + return $form; +} +function science_and_concept_map_project_details_callback($form, $form_state) +{ + $commands = array(); + $science_and_concept_map_default_value = $form_state['values']['science_and_concept_map']; + if ($science_and_concept_map_default_value != 0) { + $form['science_and_concept_map_details']['#markup'] = _science_and_concept_map_details($science_and_concept_map_default_value); + $science_and_concept_map_details = _science_and_concept_map_information($science_and_concept_map_default_value); + $provider = user_load($science_and_concept_map_details->uid); + if ($science_and_concept_map_details->uid > 0) { + $commands[] = ajax_command_html('#ajax_selected_science_and_concept_map',l('Download Abstract', "science-and-concept-map-project/download/abstract-file/" . $science_and_concept_map_default_value) . '<br>' . l('Download science and concept map', 'science-and-concept-map-project/full-download/project/' . $science_and_concept_map_default_value)); + } //$science_and_concept_map_details->uid > 0 + else { + $commands[] = ajax_command_html('#ajax_selected_science_and_concept_map', ''); + $commands[] = ajax_command_html('#ajax_selected_science_and_concept_map_soul', ''); + } + $commands[] = ajax_command_html('#ajax_science_and_concept_map_details', _science_and_concept_map_details($science_and_concept_map_default_value)); + } //$science_and_concept_map_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_science_and_concept_map_details', ''); + $commands[] = ajax_command_html('#ajax_selected_science_and_concept_map', ''); + $commands[] = ajax_command_html('#ajax_selected_science_and_concept_map_soul', ''); + $commands[] = ajax_command_data('#ajax_selected_science_and_concept_map', 'form_state_value_select', $form_state['values']['science_and_concept_map']); + } + return array( + '#type' => 'ajax', + '#commands' => $commands + ); +} +function bootstrap_table_format($headers, $rows) +{ + $thead = ""; + $tbody = ""; + foreach ($headers as $header) { + $thead .= "<th>{$header}</th>"; + } //$headers as $header + foreach ($rows as $row) { + $tbody .= "<tr>"; + foreach ($row as $data) { + $tbody .= "<td>{$data}</td>"; + } //$row as $data + $tbody .= "</tr>"; + } //$rows as $row + $table = " + <table class='table table-bordered table-hover' style='margin-left:-140px'> + <thead>{$thead}</thead> + <tbody>{$tbody}</tbody> + </table> + "; + return $table; +} +/*****************************************************/ +function _list_of_science_and_concept_map() +{ + $science_and_concept_map_titles = array( + '0' => 'Please select...' + ); + //$lab_titles_q = db_query("SELECT * FROM {science_and_concept_map_proposal} WHERE solution_display = 1 ORDER BY lab_title ASC"); + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_proposal'); + $query->condition('approval_status', 3); + $query->orderBy('project_title', 'ASC'); + $science_and_concept_map_titles_q = $query->execute(); + while ($science_and_concept_map_titles_data = $science_and_concept_map_titles_q->fetchObject()) { + $science_and_concept_map_titles[$science_and_concept_map_titles_data->id] = $science_and_concept_map_titles_data->project_title . ' (Proposed by ' . $science_and_concept_map_titles_data->name_title . ' ' . $science_and_concept_map_titles_data->contributor_name . ')'; + } //$science_and_concept_map_titles_data = $science_and_concept_map_titles_q->fetchObject() + return $science_and_concept_map_titles; +} +function _science_and_concept_map_information($proposal_id) +{ + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_proposal'); + $query->condition('id', $proposal_id); + $query->condition('approval_status', 3); + $science_and_concept_map_q = $query->execute(); + $science_and_concept_map_data = $science_and_concept_map_q->fetchObject(); + if ($science_and_concept_map_data) { + return $science_and_concept_map_data; + } //$science_and_concept_map_data + else { + return 'Not found'; + } +} +function _science_and_concept_map_details($science_and_concept_map_default_value) +{ + $science_and_concept_map_details = _science_and_concept_map_information($science_and_concept_map_default_value); + if ($science_and_concept_map_default_value != 0) { + if($science_and_concept_map_details->reference != NULL){ + $url = '~(?:(https?)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+))(?<![\.,:])~i'; + $reference = preg_replace($url, '<a href="$0" target="_blank" title="$0">$0</a>', $science_and_concept_map_details->reference); + }else{ + $reference = 'Not provided'; + } + $form['science_and_concept_map_details']['#markup'] = '<span style="color: rgb(128, 0, 0);"><strong>About the science and concept map</strong></span></td><td style="width: 35%;"><br />' . '<ul>' . '<li><strong>Proposer Name:</strong> ' . $science_and_concept_map_details->name_title . ' ' . $science_and_concept_map_details->contributor_name . '</li>' . '<li><strong>Title of the science and concept map:</strong> ' . '<span style="color: #5D125D;">' .$science_and_concept_map_details->project_title. '</li>' . '<li><strong>University:</strong> ' . $science_and_concept_map_details->university . '</li>' . '<li><strong>Category:</strong> ' . $science_and_concept_map_details->category . '</li>' . '<li>'.'<strong>Reference:</strong> ' . $reference .'</li>'.'</ul>'; + $details = $form['science_and_concept_map_details']['#markup']; + return $details; + } //$science_and_concept_map_default_value != 0 +}
\ No newline at end of file diff --git a/science_and_concept_map.info b/science_and_concept_map.info new file mode 100755 index 0000000..3e2d5e2 --- /dev/null +++ b/science_and_concept_map.info @@ -0,0 +1,7 @@ +name = "Science and Concept Map Project" +description = "Soul Project, FOSSEE, IIT Bombay" +package = FOSSEE +version = "7.x" +core = "7.x" + +;scripts[] = js/jquery-1.4.1.min.js
\ No newline at end of file diff --git a/science_and_concept_map.install b/science_and_concept_map.install new file mode 100644 index 0000000..bf6988c --- /dev/null +++ b/science_and_concept_map.install @@ -0,0 +1,618 @@ +<?php +// $Id$ +/** + * Implementation of hook_install(). + */ +function science_and_concept_map_install() + { + // Create tables. + drupal_install_schema('science_and_concept_map'); + variable_set('science_and_concept_map_emails', ''); + variable_set('science_and_concept_map_from_email', ''); + variable_set('science_and_concept_map_abstract_upload_extensions', ''); + variable_set('science_and_concept_map_report_upload_extensions', ''); + variable_set('science_and_concept_map_code_files_extensions', ''); + // create uploads folder + $upload_path = $_SERVER['DOCUMENT_ROOT'] . base_path() . 'soul_uploads/science_and_concept_map_uploads/'; + if (!is_dir($upload_path)) + mkdir($upload_path); + } +/** + * Implementation of hook_uninstall(). + */ +function science_and_concept_map_uninstall() + { + // Remove tables. + drupal_uninstall_schema('science_and_concept_map'); + // Remove variables + variable_del('science_and_concept_map_emails'); + variable_del('science_and_concept_map_from_email'); + variable_del('science_and_concept_map_abstract_upload_extensions'); + variable_del('science_and_concept_map_report_upload_extensions'); + variable_del('science_and_concept_map_code_files_extensions'); + } +/** + * Implementation of hook_schema(). + */ + +function science_and_concept_map_schema() + { + /*proposal*/ + $schema['soul_science_and_concept_map_proposal'] = array( + 'description' => t('TODO: please describe this table!'), + 'fields' => array( + 'id' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'serial', + 'not null' => TRUE + ), + 'uid' => array( + 'description' => t('TODO: please describe this field'), + 'type' => 'int', + 'not null' => TRUE + ), + 'approver_uid' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'not null' => TRUE + ), + 'name_title' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '5', + 'not null' => TRUE + ), + 'contributor_name' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '255', + 'not null' => TRUE + ), + 'contact_no' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '15', + 'not null' => TRUE + ), + 'university' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'text', + 'not null' => TRUE + ), + 'department' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'text', + 'not null' => TRUE + ), + 'city' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '100', + 'not null' => TRUE + ), + 'pincode' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '10', + 'not null' => TRUE + ), + 'state' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '100', + 'default value' => 'NONE', + 'not null' => TRUE + ), + 'country' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '100', + 'default value' => 'NONE', + 'not null' => TRUE + ), + 'options' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '200', + 'not null' => TRUE + ), + 'project_guide_name' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '255', + 'not null' => TRUE + ), + 'project_guide_department' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'text', + 'not null' => TRUE + ), + 'project_guide_email_id' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '255', + 'default value' => 'NULL', + 'not null' => TRUE + ), + 'project_title' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '255', + 'not null' => TRUE + ), + 'description' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'text', + 'not null' => TRUE + ), + 'software_version' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '50', + 'not null' => TRUE + ), + 'directory_name' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '255', + 'not null' => TRUE + ), + 'approval_status' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ), + 'is_submitted' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ), + 'is_completed' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'default value' => '0', + 'not null' => TRUE + ), + 'dissapproval_reason' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'text', + 'not null' => TRUE + ), + 'creation_date' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ), + 'approval_date' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ), + 'form_key' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '500', + 'not null' => TRUE + ), + 'actual_completion_date' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'default value' => '0', + 'not null' => TRUE + ), + 'abstractfilepath' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'text', + 'not null' => TRUE + ), + 'reference' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'text', + 'not null' => TRUE + ), + 'expected_date_of_completion' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ) + ), + 'primary key' => array( + 'id' + ) + ); + /* solution */ + $schema['soul_science_and_concept_map_solution'] = array( + 'description' => t('TODO: please describe this table!'), + 'fields' => array( + 'id' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'serial', + 'not null' => TRUE + ), + 'experiment_id' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ), + 'approver_uid' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ), + 'code_number' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '10', + 'not null' => TRUE + ), + 'caption' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '255', + 'not null' => TRUE + ), + 'approval_date' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ), + 'approval_status' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ), + 'timestamp' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ), + 'os_used' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '50', + 'not null' => TRUE + ), + 'software_version' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '20', + 'not null' => TRUE + ), + 'toolbox_used' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '100', + 'not null' => TRUE + ) + ), + 'primary key' => array( + 'id' + ) + ); + /* solution files */ + $schema['soul_science_and_concept_map_solution_files'] = array( + 'description' => t('TODO: please describe this table!'), + 'fields' => array( + 'id' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'serial', + 'not null' => TRUE + ), + 'solution_id' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ), + 'filename' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '255', + 'not null' => TRUE + ), + 'filepath' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '500', + 'not null' => TRUE + ), + 'pdfpath' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '500', + 'default value' => 'None', + 'not null' => TRUE + ), + 'filemime' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '255', + 'not null' => TRUE + ), + 'filesize' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ), + 'filetype' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '1', + 'not null' => TRUE + ), + 'caption' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '100', + 'not null' => TRUE + ), + 'timestamp' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ) + ), + 'primary key' => array( + 'id' + ) + ); + /* dependency files - links */ + $schema['soul_science_and_concept_map_solution_dependency'] = array( + 'description' => t('TODO: please describe this table!'), + 'fields' => array( + 'id' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'serial', + 'not null' => TRUE + ), + 'solution_id' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ), + 'dependency_id' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ) + ), + 'primary key' => array( + 'id' + ) + ); + /* depedency files */ + $schema['soul_science_and_concept_map_solution_dependency_files'] = array( + 'description' => t('TODO: please describe this table!'), + 'fields' => array( + 'id' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'serial', + 'not null' => TRUE + ), + 'proposal_id' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ), + 'filename' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '255', + 'not null' => TRUE + ), + 'filepath' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '500', + 'not null' => TRUE + ), + 'filemime' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '255', + 'not null' => TRUE + ), + 'filesize' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ), + 'caption' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '100', + 'not null' => TRUE + ), + 'description' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'text', + 'size' => 'medium', + 'not null' => TRUE + ), + 'timestamp' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ) + ), + 'primary key' => array( + 'id' + ) + ); + /* qr_code */ + $schema['soul_science_and_concept_map_qr_code'] = array( + 'description' => t('TODO: please describe this table!'), + 'fields' => array( + 'id' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'serial', + 'not null' => TRUE + ), + 'proposal_id' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ), + 'qr_code' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'size' => '10', + 'not null' => TRUE + ) + ), + 'primary key' => array( + 'id' + ) + ); + /* submitted_abstracts */ + $schema['soul_science_and_concept_map_submitted_abstracts'] = array( + 'description' => t('TODO: please describe this table!'), + 'fields' => array( + 'id' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'serial', + 'not null' => TRUE + ), + 'proposal_id' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ), + 'approver_uid' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ), + 'abstract_approval_status' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ), + 'abstract_upload_date' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ), + 'abstract_approval_date' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ), + 'is_submitted' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ) + ), + 'primary key' => array( + 'id' + ) + ); + /* submitted_abstracts_file */ + $schema['soul_science_and_concept_map_submitted_abstracts_file'] = array( + 'description' => t('TODO: please describe this table!'), + 'fields' => array( + 'id' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'serial', + 'not null' => TRUE + ), + 'submitted_abstract_id' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ), + 'proposal_id' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ), + 'uid' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ), + 'approvar_uid' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ), + 'filename' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '1000', + 'not null' => TRUE + ), + 'filepath' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '1000', + 'not null' => TRUE + ), + 'filemime' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '1000', + 'not null' => TRUE + ), + 'filesize' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '1000', + 'not null' => TRUE + ), + 'filetype' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '1000', + 'not null' => TRUE + ), + 'timestamp' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ), + 'file_approval_status' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'length' => '11', + 'not null' => TRUE + ) + ), + 'primary key' => array( + 'id' + ) + ); + return $schema; + }
\ No newline at end of file diff --git a/science_and_concept_map.module b/science_and_concept_map.module new file mode 100755 index 0000000..8d2d4e3 --- /dev/null +++ b/science_and_concept_map.module @@ -0,0 +1,966 @@ +<?php +// $Id$ +require_once('general_deletion.inc'); +require_once('email.inc'); +/** + * Implementation of hook_menu(). + */ +function science_and_concept_map_menu() +{ + $items = array(); + /* PROPOSAL */ + $items['science-and-concept-map-project/proposal'] = array( + 'title' => 'Science and Concept Map Proposal Form', + 'description' => 'Science and Concept Map Proposal Form', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'science_and_concept_map_proposal_form' + ), + 'access arguments' => array( + 'soul science and concept map create proposal' + ), + 'type' => MENU_NORMAL_ITEM, + 'file' => 'proposal.inc' + ); + $items['science-and-concept-map-project/manage-proposal'] = array( + 'title' => 'Manage Science and Concept Map Proposals', + 'description' => 'Manage Science and Concept Map Proposals', + 'page callback' => 'science_and_concept_map_proposal_pending', + 'access callback' => 'user_access', + 'access arguments' => array( + 'soul science and concept map manage proposal' + ), + 'file' => 'manage_proposal.inc' + ); + $items['science-and-concept-map-project/manage-proposal/pending'] = array( + 'title' => 'Pending Proposals', + 'description' => 'Pending Soul Science and Concept Map Proposals Queue', + 'page callback' => 'science_and_concept_map_proposal_pending', + 'access callback' => 'user_access', + 'access arguments' => array( + 'soul science and concept map manage proposal' + ), + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'weight' => 1, + 'file' => 'manage_proposal.inc' + ); + $items['science-and-concept-map-project/manage-proposal/all'] = array( + 'title' => 'All Proposals', + 'description' => 'All Proposals', + 'page callback' => 'science_and_concept_map_proposal_all', + 'access callback' => 'user_access', + 'access arguments' => array( + 'soul science and concept map manage proposal' + ), + 'type' => MENU_LOCAL_TASK, + 'weight' => 4, + 'file' => 'manage_proposal.inc' + ); + $items['science-and-concept-map-project/manage-proposal/approve'] = array( + 'title' => 'Approve Proposal', + 'description' => 'Approve Proposal', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'science_and_concept_map_proposal_approval_form' + ), + 'access arguments' => array( + 'soul science and concept map manage proposal' + ), + 'type' => MENU_CALLBACK, + 'file' => 'manage_proposal.inc' + ); + $items['science-and-concept-map-project/manage-proposal/solution-proposal-approve'] = array( + 'title' => 'Approve Solution Proposal', + 'description' => 'Approve Solution Proposal', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'science_and_concept_map_solution_proposal_approval_form' + ), + 'access arguments' => array( + 'soul science and concept map manage proposal' + ), + 'type' => MENU_CALLBACK, + 'file' => 'manage_solution_proposal.inc' + ); + $items['science-and-concept-map-project/manage-proposal/edit'] = array( + 'title' => 'Edit Proposal', + 'description' => 'Edit Proposal', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'science_and_concept_map_proposal_edit_form' + ), + 'access arguments' => array( + 'soul science and concept map manage proposal' + ), + 'type' => MENU_CALLBACK, + 'file' => 'manage_proposal.inc' + ); + $items['science-and-concept-map-project/manage-proposal/status'] = array( + 'title' => 'Proposal Status', + 'description' => 'Proposal Status', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'science_and_concept_map_proposal_status_form' + ), + 'access arguments' => array( + 'soul science and concept map approve proposal' + ), + 'type' => MENU_CALLBACK, + 'file' => 'manage_proposal.inc' + ); + $items['science-and-concept-map-project/show-proposal'] = array( + 'title' => 'Soul Science and Concept Map Solution Proposal', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'science_and_concept_map_solution_proposal_form' + ), + 'access arguments' => array( + 'soul science and concept map propose solution' + ), + 'type' => MENU_CALLBACK, + 'file' => 'solution_proposal.inc' + ); + /* CODE REVIEW */ + $items['science-and-concept-map-project/code-approval'] = array( + 'title' => 'Manage Code Approval', + 'description' => 'Manage Code Approval', + 'page callback' => 'science_and_concept_map_abstract_approval', + 'access arguments' => array( + 'soul science and concept map approve code' + ), + 'type' => MENU_NORMAL_ITEM, + 'file' => 'abstract_approval.inc' + ); + $items['science-and-concept-map-project/abstract-approval/approve'] = array( + 'title' => 'Code Approval', + 'description' => 'Code Approval', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'science_and_concept_map_abstract_approval_form' + ), + 'access arguments' => array( + 'soul science and concept map approve code' + ), + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'weight' => 1, + 'file' => 'abstract_approval.inc' + ); + $items['science-and-concept-map-project/abstract-approval/bulk'] = array( + 'title' => 'Bulk Manage', + 'description' => 'Bulk Mangage', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'science_and_concept_map_abstract_bulk_approval_form' + ), + 'access arguments' => array( + 'soul science and concept map bulk manage abstract' + ), + 'type' => MENU_LOCAL_TASK, + 'weight' => 2, + 'file' => 'abstract_bulk_approval.inc' + ); + $items['science-and-concept-map-project/code-approval/bulk'] = array( + 'title' => 'Bulk Manage', + 'description' => 'Bulk Mangage', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'science_and_concept_map_bulk_approval_form' + ), + 'access arguments' => array( + 'soul science and concept map bulk manage abstract' + ), + 'type' => MENU_LOCAL_TASK, + 'weight' => 2, + 'file' => 'bulk_approval.inc' + ); + /*$items['science_and_concept_map/code_approval/dependency'] = array( + 'title' => 'Dependency', + 'description' => 'Dependency Mangage', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('science_and_concept_map_dependency_approval_form'), + 'access arguments' => array('soul science and concept map bulk manage abstract'), + 'type' => MENU_LOCAL_TASK, + 'weight' => 3, + 'file' => 'dependency_approval.inc', + );*/ + $items['science-and-concept-map-project/code-approval/upload'] = array( + 'title' => 'Upload Code', + 'description' => 'Admin Upload', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'science_and_concept_map_bulk_upload_code_form' + ), + 'access arguments' => array( + 'soul science and concept map bulk manage abstract' + ), + 'type' => MENU_CALLBACK, + 'weight' => 4, + 'file' => 'bulk_upload_code.inc' + ); + $items['science-and-concept-map-project/code-approval/notes'] = array( + 'title' => 'Notes for Reviewers', + 'description' => 'Notes for Reviewers', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'science_and_concept_map_lab_notes_form' + ), + 'access arguments' => array( + 'soul science and concept map bulk manage abstract' + ), + 'type' => MENU_CALLBACK, + 'weight' => 4, + 'file' => 'notes.inc' + ); + /* CODE UPLOAD */ + $items['science-and-concept-map-project/abstract-code'] = array( + 'title' => 'Abstract and Project Files Upload', + 'description' => 'Abstract Submission', + 'page callback' => 'science_and_concept_map_abstract', + 'access callback' => 'user_access', + 'access arguments' => array( + 'soul science and concept map upload abstract' + ), + 'file' => 'upload_code.inc' + ); + $items['science-and-concept-map-project/abstract-code/science-and-concept-map-project-list'] = array( + 'title' => 'Science and Concept Map', + 'description' => 'List Experiments', + 'page callback' => 'science_and_concept_map_abstract', + 'access arguments' => array( + 'soul science and concept map upload abstract' + ), + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'file' => 'upload_code.inc', + 'weight' => 1 + ); + $items['science-and-concept-map-project/abstract-code/upload'] = array( + 'title' => 'Abstract and Project Upload', + 'description' => 'Project Upload', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'science_and_concept_map_upload_abstract_code_form' + ), + 'access arguments' => array( + 'soul science and concept map upload abstract' + ), + 'type' => MENU_LOCAL_TASK, + 'file' => 'upload_code.inc', + 'weight' => 2 + ); + $items['science-and-concept-map-project/abstract-code/delete'] = array( + 'title' => 'Delete Solution', + 'description' => 'Delete Solution', + 'page callback' => 'science_and_concept_map_upload_code_delete', + 'access arguments' => array( + 'soul science and concept map upload code' + ), + 'type' => MENU_CALLBACK, + 'file' => 'upload_code_delete.inc' + ); + /* CODE DOWNLOADS */ + $items['science-and-concept-map-project/download/file'] = array( + 'title' => 'Code Download', + 'description' => 'Code Download', + 'page callback' => 'science_and_concept_map_download_solution_file', + 'access arguments' => array( + 'soul science and concept map download code' + ), + 'type' => MENU_CALLBACK, + 'file' => 'download.inc' + ); + $items['science-and-concept-map-project/download/solution'] = array( + 'title' => 'Code Download', + 'description' => 'Code Download', + 'page callback' => 'science_and_concept_map_download_solution', + 'access arguments' => array( + 'soul science and concept map download code' + ), + 'type' => MENU_CALLBACK, + 'file' => 'download.inc' + ); + $items['science-and-concept-map-project/download/experiment'] = array( + 'title' => 'Code Download', + 'description' => 'Code Download', + 'page callback' => 'science_and_concept_map_download_experiment', + 'access arguments' => array( + 'soul science and concept map download code' + ), + 'type' => MENU_CALLBACK, + 'file' => 'download.inc' + ); + $items['science-and-concept-map-project/download/project'] = array( + 'title' => 'Code Download', + 'description' => 'Code Download', + 'page callback' => 'science_and_concept_map_download_project', + 'access arguments' => array( + 'soul science and concept map download code' + ), + 'type' => MENU_CALLBACK, + 'file' => 'download.inc' + ); + $items['science-and-concept-map-project/full-download/experiment'] = array( + 'title' => 'Code Download', + 'description' => 'Code Download', + 'page callback' => 'science_and_concept_map_download_completed_project', + 'access arguments' => array( + 'soul science and concept map approve code' + ), + 'type' => MENU_CALLBACK, + 'file' => 'full_download.inc' + ); + $items['science-and-concept-map-project/full-download/project'] = array( + 'title' => 'Code Download', + 'description' => 'Code Download', + 'page callback' => 'science_and_concept_map_download_full_project', + 'access arguments' => array( + 'soul science and concept map download code' + ), + 'type' => MENU_CALLBACK, + 'file' => 'full_download.inc' + ); + /* COMPLETED soul science and concept maps */ + $items['science-and-concept-map-project/completed-projects'] = array( + 'title' => 'Completed Science and Concept Maps', + 'page callback' => 'science_and_concept_map_completed_proposals_all', + 'access arguments' => array( + 'soul science and concept map download code' + ), + 'file' => 'science_and_concept_map_details.inc', + ); + $items['science-and-concept-map-project/completed-projects/simulations'] = array( + 'title' => 'Completed Science and Concept Maps', + 'page callback' => 'science_and_concept_map_completed_proposals_all', + 'access arguments' => array( + 'soul science and concept map download code' + ), + 'file' => 'science_and_concept_map_details.inc', + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'weight' => 0 + ); + /* LABS IN PROGRESS */ + $items['science-and-concept-map-project/project-in-progress'] = array( + 'title' => 'Science and Concept Maps in Progress', + 'page callback' => 'science_and_concept_map_progress_all', + 'access arguments' => array( + 'soul science and concept map download code' + ), + 'file' => 'science_and_concept_map_details.inc' + ); + /* DOWNLOAD FOR EVERYONE */ + $items['science-and-concept-map-project/soul-science-and-concept-map-run'] = array( + 'title' => 'Download Codes', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'science_and_concept_map_run_form' + ), + 'access arguments' => array( + 'soul science and concept map download code' + ), + 'type' => MENU_NORMAL_ITEM, + 'file' => 'run.inc' + ); + $items['science-and-concept-map-project/download/abstract-file'] = array( + 'title' => 'Download user defined compound file', + 'description' => 'Download resource file', + 'page callback' => 'science_and_concept_map_download_upload_file', + 'access arguments' => array( + 'soul science and concept map download code' + ), + 'type' => MENU_CALLBACK, + 'file' => 'download.inc' + ); + $items['science-and-concept-map-project/download/project-file'] = array( + 'title' => 'Download Project file', + 'description' => 'Download project file', + 'page callback' => 'soul_science_and_concept_map_project_files', + 'access arguments' => array( + 'soul science and concept map download code' + ), + 'type' => MENU_CALLBACK, + 'file' => 'download.inc' + ); + /* LATEX SCRIPT */ + $items['science-and-concept-map-project/generate-lab'] = array( + 'title' => 'Generate Lab', + 'description' => 'Generate Lab From Latex Script', + 'page callback' => 'science_and_concept_map_download_lab_pdf', + 'access arguments' => array( + 'soul science and concept map generate lab' + ), + 'type' => MENU_CALLBACK, + 'file' => 'latex.inc' + ); + $items['science-and-concept-map-project/delete-lab'] = array( + 'title' => 'Delete Lab PDF', + 'description' => 'Delete Lab PDF', + 'page callback' => 'science_and_concept_map_delete_lab_pdf', + 'access arguments' => array( + 'soul science and concept map approve code' + ), + 'type' => MENU_CALLBACK, + 'file' => 'latex.inc' + ); + /* ADMIN SETTINGS */ + $items['admin/settings/soul-science and concept map'] = array( + 'title' => 'Science and Concept Map Settings', + 'description' => 'soul science and concept map Settings', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'science_and_concept_map_settings_form' + ), + 'access arguments' => array( + 'administer soul science and concept map' + ), + 'type' => MENU_NORMAL_ITEM, + 'file' => 'settings.inc' + ); + /* AJAX REQUEST */ + $items["lab-bulk-manage-exp/ajax"] = array( + "title" => "Ajax callbacks", + "page callback" => "lab_bulk_manage_exp_ajax", + "access arguments" => array( + "soul science and concept map bulk manage abstract" + ), + "type" => MENU_CALLBACK, + 'file' => 'bulk_approval.inc' + ); + $items['science-and-concept-map-project/certificates'] = array( + 'title' => 'List of science and concept map Certificates', + 'description' => 'List of science and concept map Certificates', + 'page callback' => '_list_science_and_concept_map_certificates', + 'access arguments' => array( + 'list science and concept map certificates' + ), + 'file' => 'pdf/list_science_and_concept_map_certificate.inc' + ); + $items['science-and-concept-map-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['science-and-concept-map-project/certificates-custom'] = array( + 'title' => 'List of science and concept map Custom Certificates', + 'description' => 'List of science and concept map Custom Certificates', + 'page callback' => '_list_science_and_concept_map_custom_certificates', + 'access arguments' => array( + 'list science and concept map custom certificates' + ), + 'file' => 'pdf/list_mentor_certificates.inc' + ); + $items['science-and-concept-map-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['science-and-concept-map-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 science_and_concept_map_permission() +{ + return array( + 'soul science and concept map create proposal' => array( + 'title' => t('soul science and concept map create proposal'), + 'restrict access' => TRUE + ), + 'soul science and concept map manage proposal' => array( + 'title' => t('soul science and concept map manage proposal'), + 'restrict access' => TRUE + ), + 'soul science and concept map edit proposal' => array( + 'title' => t('soul science and concept map edit proposal'), + 'restrict access' => TRUE + ), + 'soul science and concept map approve proposal' => array( + 'title' => t('soul science and concept map approve proposal'), + 'restrict access' => TRUE + ), + 'soul science and concept map propose solution' => array( + 'title' => t('soul science and concept map propose solution'), + 'restrict access' => TRUE + ), + 'soul science and concept map approve code' => array( + 'title' => t('soul science and concept map approve code'), + 'restrict access' => TRUE + ), + 'soul science and concept map bulk manage abstract' => array( + 'title' => t('soul science and concept map bulk manage abstract'), + 'restrict access' => TRUE + ), + 'soul science and concept map bulk delete abstract' => array( + 'title' => t('soul science and concept map bulk delete code'), + 'restrict access' => TRUE + ), + 'soul science and concept map upload abstract' => array( + 'title' => t('soul science and concept map upload code'), + 'restrict access' => TRUE + ), + 'soul science and concept map download code' => array( + 'title' => t('soul science and concept map download code'), + 'restrict access' => TRUE + ), + 'administer soul science and concept map' => array( + 'title' => t('administer soul science and concept map'), + 'restrict access' => TRUE + ), + 'soul science and concept map generate abstract' => array( + 'title' => t('soul science and concept map generate abstract'), + 'restrict access' => TRUE + ), + "list science and concept map certificates" => array( + "title" => t("list the certificates"), + "description" => t("list the certificates"), + 'restrict access' => TRUE + ), + "list science and concept map 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 + ) + + ); + // return array('soul science and concept map create proposal', 'soul science and concept map manage proposal', 'soul science and concept map edit proposal', 'soul science and concept map approve proposal', 'soul science and concept map propose solution', 'soul science and concept map approve code', 'soul science and concept map bulk manage abstract', 'soul science and concept map bulk delete code', 'soul science and concept map upload code', 'soul science and concept map download code', 'administer soul science and concept map', 'soul science and concept map generate lab'); +} +/* AJAX CALLS */ +/*function science_and_concept_map_ajax() +{ + $query_type = arg(2); + if ($query_type == 'chapter_title') + { + $chapter_number = arg(3); + $preference_id = arg(4); + //$chapter_q = db_query("SELECT * FROM {soul_science_and_concept_map_chapter} WHERE number = %d AND preference_id = %d LIMIT 1", $chapter_number, $preference_id); + $query = db_select('soul_science_and_concept_map_chapter'); + $query->fields('soul_science_and_concept_map_chapter'); + $query->condition('number', $chapter_number); + $query->condition('preference_id', $preference_id); + $query->range(0, 1); + $chapter_q = $query->execute(); + if ($chapter_data = $chapter_q->fetchObject()) + { + echo $chapter_data->name; + return; + } //$chapter_data = $chapter_q->fetchObject() + } //$query_type == 'chapter_title' + else if ($query_type == 'example_exists') + { + $chapter_number = arg(3); + $preference_id = arg(4); + $example_number = arg(5); + $chapter_id = 0; + $query = db_select('soul_science_and_concept_map_chapter'); + $query->fields('soul_science_and_concept_map_chapter'); + $query->condition('number', $chapter_number); + $query->condition('preference_id', $preference_id); + $query->range(0, 1); + $chapter_q = $query->execute(); + if (!$chapter_data = $chapter_q->fetchObject()) + { + echo ''; + return; + } //!$chapter_data = $chapter_q->fetchObject() + else + { + $chapter_id = $chapter_data->id; + } + $query = db_select('soul_science_and_concept_map_example'); + $query->fields('soul_science_and_concept_map_example'); + $query->condition('chapter_id', $chapter_id); + $query->condition('number', $example_number); + $query->range(0, 1); + $example_q = $query->execute(); + if ($example_data = $example_q->fetchObject()) + { + if ($example_data->approval_status == 1) + echo 'Warning! Solution already approved. You cannot upload the same solution again.'; + else + echo 'Warning! Solution already uploaded. Delete the solution and reupload it.'; + return; + } //$example_data = $example_q->fetchObject() + } //$query_type == 'example_exists' + echo ''; +}*/ +/*************************** VALIDATION FUNCTIONS *****************************/ +function science_and_concept_map_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 science_and_concept_map_check_name($name = '') +{ + if (!preg_match('/^[0-9a-zA-Z\ ]+$/', $name)) + return FALSE; + else + return TRUE; +} +function science_and_concept_map_check_code_number($number = '') +{ + if (!preg_match('/^[0-9]+$/', $number)) + return FALSE; + else + return TRUE; +} +function science_and_concept_map_path() +{ + return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'soul_uploads/science_and_concept_map_uploads/'; +} +function science_and_concept_map_file_path($value='') +{ + return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'soul_uploads/'; +} +/************************* USER VERIFICATION FUNCTIONS ************************/ +function science_and_concept_map_get_proposal() +{ + global $user; + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_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 soul science and concept map proposal. Please propose the science and concept map proposal", '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 _df_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 _df_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 _df_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 _df_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 _df_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 _soul_list_of_category() + { + $category = array(); + $query = db_select('soul_science_and_concept_map_category'); + $query->fields('soul_science_and_concept_map_category'); + $category_list = $query->execute(); + while ($category_list_data = $category_list->fetchObject()) + { + $category[$category_list_data->category] = $category_list_data->category; + } + return $category; + } + +function _soul_list_of_sub_category() +{ + $sub_category = array( + 0 => '-Select-' + ); + $query = db_select('soul_science_and_concept_map_sub_category'); + $query->fields('soul_science_and_concept_map_sub_category'); + $sub_category_list = $query->execute(); + while ($sub_category_list_data = $sub_category_list->fetchObject()) + { + $sub_category[$sub_category_list_data->sub_category] = $sub_category_list_data->sub_category; + } //$city_list_data = $city_list->fetchObject() + return $sub_category; +} + +function _soul_list_of_software_version() + { + $software_version = array(); + $query = db_select('soul_science_and_concept_map_software_version'); + $query->fields('soul_science_and_concept_map_software_version'); + $software_version_list = $query->execute(); + while ($software_version_list_data = $software_version_list->fetchObject()) + { + $software_version[$software_version_list_data->id] = $software_version_list_data->software_versions; + } + return $software_version; + } + + +function _soul_list_of_software_version_details($software_version_id) +{ + $software_version_id = $software_version_id; + $software_versions = array( + 0 => '-Select-' + ); + $query = db_select('soul_science_and_concept_map_software_version_details'); + $query->fields('soul_science_and_concept_map_software_version_details'); + $query->condition('software_version_id',$software_version_id); + $software_versions_list = $query->execute(); + while($software_versions_data = $software_versions_list->fetchObject()){ + $software_versions[$software_versions_data->software_version_name] = $software_versions_data->software_version_name; + } + return $software_versions; +} + +function _df_dir_name($project, $proposar_name) +{ + $project_title = ucname($project); + $proposar_name = ucname($proposar_name); + $dir_name = $project_title . ' By ' . $proposar_name; + $directory_name = str_replace("__", "_", str_replace(" ", "_", str_replace("/","_", trim($dir_name)))); + return $directory_name; +} +function science_and_concept_map_document_path() +{ + return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'soul_uploads/science_and_concept_map_uploads/'; +} +function DF_RenameDir($proposal_id, $dir_name) +{ + $proposal_id = $proposal_id; + $dir_name = $dir_name; + $query = db_query("SELECT directory_name,id FROM soul_science_and_concept_map_proposal WHERE id = :proposal_id", array( + ':proposal_id' => $proposal_id + )); + $result = $query->fetchObject(); + if ($result != NULL) + { + $files = scandir(science_and_concept_map_path()); + $files_id_dir = science_and_concept_map_path() . $result->id; + //var_dump($files);die; + $file_dir = science_and_concept_map_path() . $result->directory_name; + if (is_dir($file_dir)) + { + $new_directory_name = rename(science_and_concept_map_path() . $result->directory_name, science_and_concept_map_path() . $dir_name); + return $new_directory_name; + } //is_dir($file_dir) + else if (is_dir($files_id_dir)) + { + $new_directory_name = rename(science_and_concept_map_path() . $result->id, science_and_concept_map_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 CreateReadmeFileSoulScienceAndConceptMapProject($proposal_id) +{ + $result = db_query(" + SELECT * from soul_science_and_concept_map_proposal WHERE id = :proposal_id", array( + ":proposal_id" => $proposal_id + )); + $proposal_data = $result->fetchObject(); + $root_path = science_and_concept_map_path(); + $readme_file = fopen($root_path . $proposal_data->directory_name . "/README.txt", "w") or die("Unable to open file!"); + $txt = ""; + $txt .= "About the science and concept map"; + $txt .= "\n" . "\n"; + $txt .= "Title Of The science and concept map 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 .= "soul science and concept map 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 soul_science_and_concept_map_proposal WHERE id = :proposal_id", array( + ":proposal_id" => $proposal_id + )); + $proposal_data = $result->fetchObject(); + $root_path = science_and_concept_map_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) +}
\ No newline at end of file diff --git a/science_and_concept_map_details.inc b/science_and_concept_map_details.inc new file mode 100755 index 0000000..ea8f0b2 --- /dev/null +++ b/science_and_concept_map_details.inc @@ -0,0 +1,100 @@ +<?php +// soul science and concept map display completed proposals +function science_and_concept_map_completed_proposals_all() +{ + $output = ""; + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_proposal'); + $query->condition('approval_status', 3); + $query->orderBy('actual_completion_date', 'DESC'); + //$query->condition('is_completed', 1); + $result = $query->execute(); + + //var_dump($soul_project_abstract);die; + if ($result->rowCount() == 0) + { + $output .= "Work has been completed for the following science and concept map. We welcome your contributions." ."<hr>"; + + } //$result->rowCount() == 0 + else + { + $output .= "Work has been completed for the following science and concept map. We welcome your contributions." . "<hr>"; + $preference_rows = array(); + $i = 1; + while ($row = $result->fetchObject()) + { + $proposal_id = $row->id; + $query1 = db_select('soul_science_and_concept_map_submitted_abstracts_file'); + $query1->fields('soul_science_and_concept_map_submitted_abstracts_file'); + $query1->condition('file_approval_status', 1); + $query1->condition('proposal_id', $proposal_id); + $soul_project_files = $query1->execute(); + $soul_project_abstract = $soul_project_files->fetchObject(); + $completion_date = date("Y", $row->actual_completion_date); + $preference_rows[] = array( + $i, + l($row->project_title, "science-and-concept-map-project/soul-science-and-concept-map-run/" . $row->id), + $row->contributor_name, + $row->university, + $completion_date + ); + $i++; + } //$row = $result->fetchObject() + $preference_header = array( + 'No', + 'science and concept map Project', + 'Contributor Name', + 'University / Institute', + 'Year of Completion' + ); + $output .= theme('table', array( + 'header' => $preference_header, + 'rows' => $preference_rows + )); + } + return $output; +} +// soul science and concept map display in progress proposals +function science_and_concept_map_progress_all() +{ + $page_content = ""; + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_proposal'); + $query->condition('approval_status', 1); + $query->condition('is_completed', 0); + $result = $query->execute(); + if ($result->rowCount() == 0) + { + $page_content .= "Work is in progress for the following science and concept map under science and concept map Project<hr>"; + } //$result->rowCount() == 0 + else + { + $page_content .= "Work is in progress for the following science and concept map under science and concept map Project<hr>"; + $preference_rows = array(); + $i = 1; + 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', + 'science and concept map Project', + 'Contributor Name', + 'Institute', + '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 100755 index 0000000..386f0d4 --- /dev/null +++ b/settings.inc @@ -0,0 +1,78 @@ +<?php +// $Id$ +function science_and_concept_map_settings_form($form, $form_state) +{ + $form['emails'] = array( + '#type' => 'textfield', + '#title' => t('(Bcc) Notification emails'), + '#description' => t('Specify emails id for Bcc option of mail system with comma separated'), + '#size' => 50, + '#maxlength' => 255, + '#required' => TRUE, + '#default_value' => variable_get('science_and_concept_map_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('science_and_concept_map_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('science_and_concept_map_from_email', '') + ); + $form['extensions']['abstract_upload'] = array( + '#type' => 'textfield', + '#title' => t('Allowed file extensions for uploading abstract file'), + '#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('science_and_concept_map_abstract_upload_extensions', '') + ); + $form['extensions']['report_upload'] = array( + '#type' => 'textfield', + '#title' => t('Allowed file extensions for report'), + '#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('science_and_concept_map_report_upload_extensions', '') + ); + $form['extensions']['science_and_concept_map_code_upload'] = array( + '#type' => 'textfield', + '#title' => t('Allowed extensions for code 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('science_and_concept_map_code_files_extensions', '') + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); + return $form; +} +function science_and_concept_map_settings_form_validate($form, &$form_state) +{ + return; +} +function science_and_concept_map_settings_form_submit($form, &$form_state) +{ + variable_set('science_and_concept_map_emails', $form_state['values']['emails']); + variable_set('science_and_concept_map_cc_emails', $form_state['values']['cc_emails']); + variable_set('science_and_concept_map_from_email', $form_state['values']['from_email']); + variable_set('science_and_concept_map_abstract_upload_extensions', $form_state['values']['abstract_upload']); + variable_set('science_and_concept_map_report_upload_extensions', $form_state['values']['report_upload']); + variable_set('science_and_concept_map_code_files_extensions', $form_state['values']['science_and_concept_map_code_upload']); + drupal_set_message(t('Settings updated'), 'status'); +}
\ No newline at end of file diff --git a/upload_code.inc b/upload_code.inc new file mode 100755 index 0000000..c70ee6e --- /dev/null +++ b/upload_code.inc @@ -0,0 +1,549 @@ +<?php +// $Id$ +function science_and_concept_map_abstract() +{ + global $user; + $return_html = ""; + $proposal_data = science_and_concept_map_get_proposal(); + if (!$proposal_data) + { + drupal_goto(''); + return; + } //!$proposal_data + //$return_html .= l('Upload abstract', 'science-and-concept-map-project/abstract-code/upload') . '<br />'; + /* get experiment list */ + $query = db_select('soul_science_and_concept_map_submitted_abstracts'); + $query->fields('soul_science_and_concept_map_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 project files, hence you can not upload more code, for any query please write to us.'), 'error', $repeat = FALSE); + //drupal_goto('circuit-simulation-project/abstract-code'); + //return; + } //$abstracts_q->is_submitted == 1 + }*/ //$abstracts_q + $query_pro = db_select('soul_science_and_concept_map_proposal'); + $query_pro->fields('soul_science_and_concept_map_proposal'); + $query_pro->condition('id', $proposal_data->id); + $abstracts_pro = $query_pro->execute()->fetchObject(); + $query_pdf = db_select('soul_science_and_concept_map_submitted_abstracts_file'); + $query_pdf->fields('soul_science_and_concept_map_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, 'circuit-simulation-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('soul_science_and_concept_map_submitted_abstracts_file'); + $query_process->fields('soul_science_and_concept_map_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, 'circuit-simulation-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 abstract', 'science-and-concept-map-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', 'science-and-concept-map-project/abstract-code/upload'); + } //$abstracts_q->is_submitted == 0 + } //$abstracts_query_process == TRUE + else + { + $url = l('Upload abstract', 'science-and-concept-map-project/abstract-code/upload'); + $abstracts_query_process_filename = "File not uploaded"; + } + $return_html .= '<strong>Contributor Name:</strong><br />' . $proposal_data->name_title . ' ' . $proposal_data->contributor_name . '<br /><br />'; + $return_html .= '<strong>Title of the science and concept map Project:</strong><br />' . $proposal_data->project_title . '<br /><br />'; + $return_html .= '<strong>Title of the Category:</strong><br />' . $proposal_data->category . '<br /><br />'; + $return_html .= '<strong>Uploaded Report file of the project:</strong><br />' . $abstract_filename . '<br /><br />'; + $return_html .= '<strong>Uploaded project files of the project:</strong><br />' . $abstracts_query_process_filename . '<br /><br />'; + $return_html .= $url . '<br />'; + $return_html .='<br />'; + $return_html .='Prepare a Project directory in a .zip folder. The directory should contain:' .'<br /><br />'. + '<ol>'. + +'<li>'.'Data file/s: Please provide completed project files pertaining to the software'. '</li>'. + + +'<li>'.'Creating Concept Maps using Freeplane must provide files in .mm format and supporting data files if any. Please mention the software version used to generate the data files for this project'. '</li>'. + + +'<li>'.'3D modelling projects using Jmol Application or Avogadro must provide files in .mol file format. Projects using UCSF-Chimera must provide files in .pdb format. Please mention the software version used to generate the data files for this project'. '</li>'. + + +'<li>'.'Mathematical Applications Project using Geogebra must provide files in .ggb file format. Please mention the software version used to generate the data files for this project'. '</li>'. + + +'<li>'.'Chemistry Lab Project using ChemCollective vlabs must provide Image files as screenshots in JPEG, PNG or PDF format for every step. You may consider recording a video with audio in MP4 format and also submit a media file. Please mention the software version used to generate the data files for this project.'.'</li>' .'<ol>' ; + + + return $return_html; +} + +function science_and_concept_map_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('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_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('science-and-concept-map-project/abstract-code'); + return; + } + } //$proposal_q + else + { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('science-and-concept-map-project/abstract-code'); + return; + } + $query = db_select('soul_science_and_concept_map_submitted_abstracts'); + $query->fields('soul_science_and_concept_map_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 project files, hence you can not upload more code, for any query please write to us.'), 'error', $repeat = FALSE); + drupal_goto('science-and-concept-map-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 science and concept map Project') + ); + $form['contributor_name'] = array( + '#type' => 'item', + '#markup' => $proposal_data->contributor_name, + '#title' => t('Contributor Name') + ); + $form['category'] = array( + '#type' => 'item', + '#markup' => $proposal_data->category, + '#title' => t('Category 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_an_report'] = array( + '#type' => 'file', + '#title' => t('Upload the report.') , + '#description' => t('<span style="color:red;">Current File :</span> ' . $existing_uploaded_A_file->filename . '<br />' . t('<span style="color:red;">Allowed file extensions : ') . variable_get('science_and_concept_map_report_upload_extensions', '') . '</span>' + )); + $existing_uploaded_S_file = default_value_for_uploaded_files("S", $proposal_data->id); + if (!$existing_uploaded_S_file) + { + $existing_uploaded_S_file = new stdClass(); + $existing_uploaded_S_file->filename = "No file uploaded"; + } //!$existing_uploaded_S_file + $form['upload_science_and_concept_map_code_files'] = array( + '#type' => 'file', + '#title' => t('Upload the Project file'), + '#description' => t('<span style="color:red;">Current File :</span> ' . $existing_uploaded_S_file->filename . '<br />Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . t('<span style="color:red;">Allowed file extensions : ') . variable_get('science_and_concept_map_code_files_extensions', '') . '</span>' + ); + $form['prop_id'] = array( + '#type' => 'hidden', + '#value' => $proposal_data->id + );/* + $form['is_submitted'] = array( + '#type' => 'checkboxes', + //'#title' => t('Terms And Conditions'), + '#options' => array( + 'status' => t('I have uploaded the project files') + ), + '#required' => TRUE + );*/ + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit'), + '#submit' => array( + 'science_and_concept_map_upload_abstract_code_form_submit' + ) + ); + $form['cancel'] = array( + '#type' => 'item', + '#markup' => l(t('Cancel'), 'science-and-concept-map-project/abstract-code') + ); + return $form; +} + +/////////////////////////////////////////////////////////////// +function science_and_concept_map_upload_abstract_code_form_validate($form, &$form_state) +{ + if (isset($_FILES['files'])) + { + /* check if file is uploaded */ + $existing_uploaded_A_file = default_value_for_uploaded_files("A", $form_state['values']['prop_id']); + $existing_uploaded_S_file = default_value_for_uploaded_files("S", $form_state['values']['prop_id']); + if (!$existing_uploaded_S_file) + { + if (!($_FILES['files']['name']['upload_science_and_concept_map_code_files'])) + form_set_error('upload_science_and_concept_map_code_files', t('Please upload the file.')); + } //!$existing_uploaded_S_file + if (!$existing_uploaded_A_file) + { + if (!($_FILES['files']['name']['upload_an_report'])) + form_set_error('upload_an_report', t('Please upload the file.')); + } //!$existing_uploaded_A_file + /* check for valid filename extensions */ + if ($_FILES['files']['name']['upload_an_udc'] || $_FILES['files']['name']['upload_an_report'] || $_FILES['files']['name']['upload_science_and_concept_map_code_files']) + { + foreach ($_FILES['files']['name'] as $file_form_name => $file_name) + { + if ($file_name) + { + /* checking file type */ + if (strstr($file_form_name, 'upload_science_and_concept_map_code_files')) + $file_type = 'S'; + else if (strstr($file_form_name, 'upload_an_report')) + $file_type = 'A'; + else + $file_type = 'U'; + $allowed_extensions_str = ''; + switch ($file_type) + { + case 'S': + $allowed_extensions_str = variable_get('science_and_concept_map_code_files_extensions', ''); + break; + case 'A': + $allowed_extensions_str = variable_get('science_and_concept_map_report_upload_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 (!science_and_concept_map_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 + } //$_FILES['files']['name'] as $file_form_name => $file_name + } //isset($_FILES['files']) + // drupal_add_js('jQuery(document).ready(function () { alert("Hello!"); });', 'inline'); + // drupal_static_reset('drupal_add_js') ; +} +function science_and_concept_map_upload_abstract_code_form_submit($form, &$form_state) +{ + global $user; + $v = $form_state['values']; + $root_path = science_and_concept_map_path(); + $proposal_data = science_and_concept_map_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_project_files = $proposal_directory . '/project_files/'; + if (!is_dir($root_path . $dest_path_project_files)) + mkdir($root_path . $dest_path_project_files); + $proposal_id = $proposal_data->id; + $query_s = "SELECT * FROM {soul_science_and_concept_map_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 {soul_science_and_concept_map_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 {soul_science_and_concept_map_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 {soul_science_and_concept_map_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 {soul_science_and_concept_map_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_science_and_concept_map_code_files')) + { + $file_type = 'S'; + } //strstr($file_form_name, 'upload_science_and_concept_map_code_files') + else if (strstr($file_form_name, 'upload_an_report')) + { + $file_type = 'A'; + } + else + { + $file_type = 'U'; + } + switch ($file_type) + { + case 'S': + if (file_exists($root_path . $dest_path_project_files . $_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_project_files . $_FILES['files']['name'][$file_form_name])) + { + /* for uploaded files making an entry in the database */ + $query_ab_f = "SELECT * FROM soul_science_and_concept_map_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 {soul_science_and_concept_map_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_project_files . $_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_project_files . $query_ab_f_result->filename); + $query = "UPDATE {soul_science_and_concept_map_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); + 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_project_files . $file_name, 'error'); + } + break; + case 'A': + if (file_exists($root_path . $dest_path_project_files . $_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_project_files . $_FILES['files']['name'][$file_form_name])) + { + /* for uploaded files making an entry in the database */ + $query_ab_f = "SELECT * FROM soul_science_and_concept_map_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 {soul_science_and_concept_map_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_project_files . $_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_project_files . $query_ab_f_result->filename); + $query = "UPDATE {soul_science_and_concept_map_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); + 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_project_files . $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('science_and_concept_map_from_email', ''); + $bcc = variable_get('science_and_concept_map_emails', ''); + $cc = variable_get('science_and_concept_map_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('science_and_concept_map', 'abstract_uploaded', $email_to, language_default(), $params, $from, TRUE)) + drupal_set_message('Error sending email message.', 'error'); + drupal_goto('science-and-concept-map-project/abstract-code'); +} +function default_value_for_uploaded_files($filetype, $proposal_id) +{ + $query = db_select('soul_science_and_concept_map_submitted_abstracts_file'); + $query->fields('soul_science_and_concept_map_submitted_abstracts_file'); + $query->condition('proposal_id', $proposal_id); + $selected_files_array = ""; + if ($filetype == "A") + { + $query->condition('filetype', $filetype); + $filetype_q = $query->execute()->fetchObject(); + return $filetype_q; + } //$filetype == "A" + elseif ($filetype == "S") + { + $query->condition('filetype', $filetype); + $filetype_q = $query->execute()->fetchObject(); + return $filetype_q; + } + else + { + return; + } + return; +}
\ No newline at end of file diff --git a/upload_code_delete.inc b/upload_code_delete.inc new file mode 100755 index 0000000..21ad127 --- /dev/null +++ b/upload_code_delete.inc @@ -0,0 +1,95 @@ +<?php + +/******************************************************************************/ +/***************************** DELETE CODE ************************************/ +/******************************************************************************/ + +function soul_science_and_concept_map_upload_code_delete() +{ + global $user; + + $root_path = science_and_concept_map_path(); + $solution_id = (int)arg(3); + + /* check solution */ + // $solution_q = db_query("SELECT * FROM {soul_science_and_concept_map_solution} WHERE id = %d LIMIT 1", $solution_id); + $query = db_select('soul_science_and_concept_map_solution'); + $query->fields('soul_science_and_concept_map_solution'); + $query->condition('id', $solution_id); + $query->range(0, 1); + $solution_q = $query->execute(); + $solution_data = $solution_q->fetchObject(); + if (!$solution_data) + { + drupal_set_message('Invalid solution.', 'error'); + drupal_goto('science-and-concept-map-project/code'); + return; + } + if ($solution_data->approval_status != 0) + { + drupal_set_message('You cannnot delete a solution after it has been approved. Please contact site administrator if you want to delete this solution.', 'error'); + drupal_goto('science-and-concept-map-project/code'); + return; + } + + //$experiment_q = db_query("SELECT * FROM {soul_science_and_concept_map_experiment} WHERE id = %d LIMIT 1", $solution_data->experiment_id); + $query = db_select('soul_science_and_concept_map_experiment'); + $query->fields('soul_science_and_concept_map_experiment'); + $query->condition('id', $solution_data->experiment_id); + $query->range(0, 1); + $experiment_q = $query->execute(); + + $experiment_data = $experiment_q->fetchObject(); + if (!$experiment_data) + { + drupal_set_message('You do not have permission to delete this solution.', 'error'); + drupal_goto('science-and-concept-map-project/code'); + return; + } + + //$proposal_q = db_query("SELECT * FROM {soul_science_and_concept_map_proposal} WHERE id = %d AND solution_provider_uid = %d LIMIT 1", $experiment_data->proposal_id, $user->uid); + $query = db_select('soul_science_and_concept_map_proposal'); + $query->fields('soul_science_and_concept_map_proposal'); + $query->condition('id', $experiment_data->proposal_id); + $query->condition('solution_provider_uid', $user->uid); + $query->range(0, 1); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + if (!$proposal_data) + { + drupal_set_message('You do not have permission to delete this solution.', 'error'); + drupal_goto('science-and-concept-map-project/code'); + return; + } + + /* deleting solution files */ + if (soul_science_and_concept_map_delete_solution($solution_data->id)) + { + drupal_set_message('Solution deleted.', 'status'); + + /* sending email */ + $email_to = $user->mail; + + $from = variable_get('soul_science_and_concept_map_from_email', ''); + $bcc= variable_get('soul_science_and_concept_map_emails', ''); + $cc=variable_get('soul_science_and_concept_map_cc_emails', ''); + + $param['solution_deleted_user']['lab_title'] = $proposal_data->lab_title; + $param['solution_deleted_user']['experiment_title'] = $experiment_data->title; + $param['solution_deleted_user']['solution_number'] = $solution_data->code_number; + $param['solution_deleted_user']['solution_caption'] = $solution_data->caption; + $param['solution_deleted_user']['user_id'] = $user->uid; + $param['solution_deleted_user']['headers']=array('From'=>$from,'MIME-Version'=> '1.0', + 'Content-Type'=> 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer'=> 'Drupal','Cc' => $cc, 'Bcc' => $bcc); + + if (!drupal_mail('soul_science_and_concept_map', 'solution_deleted_user', $email_to, language_default(), $param , $from , TRUE)) + drupal_set_message('Error sending email message.', 'error'); + } else { + drupal_set_message('Error deleting example.', 'status'); + } + + drupal_goto('science-and-concept-map-project/code'); + return; +}
\ No newline at end of file |