diff options
-rwxr-xr-x | abstract_bulk_approval.inc | 17 | ||||
-rw-r--r-- | add_project_titles.inc | 120 | ||||
-rw-r--r-- | available_project_titles_list.inc | 33 | ||||
-rwxr-xr-x | cfd_case_study.module | 47 | ||||
-rwxr-xr-x | cfd_case_study_details.inc | 2 | ||||
-rwxr-xr-x | proposal.inc | 64 | ||||
-rwxr-xr-x | settings.inc | 10 |
7 files changed, 278 insertions, 15 deletions
diff --git a/abstract_bulk_approval.inc b/abstract_bulk_approval.inc index 87ba9f0..2989777 100755 --- a/abstract_bulk_approval.inc +++ b/abstract_bulk_approval.inc @@ -254,19 +254,18 @@ FOSSEE,IIT Bombay', array( )); $email_body = array( 0 => t(' +Dear !user_name, - Dear !user_name, - - Your uploaded case study project files for the case study project Title : ' . $user_info->project_title . ' have been marked as dis-approved. +Your uploaded case study project files for the case study project Title : ' . $user_info->project_title . ' have been marked as dis-approved. - Reason for dis-approval: ' . $form_state['values']['message'] . ' +Reason for dis-approval: ' . $form_state['values']['message'] . ' - Best Wishes, +Best Wishes, - !site_name Team, - FOSSEE,IIT Bombay', array( - '!site_name' => variable_get('site_name', ''), - '!user_name' => $user_data->name +!site_name Team, +FOSSEE,IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name )) ); $email_to = $user_data->mail; diff --git a/add_project_titles.inc b/add_project_titles.inc new file mode 100644 index 0000000..257e9b5 --- /dev/null +++ b/add_project_titles.inc @@ -0,0 +1,120 @@ +<?php +function add_project_title_form($form, &$form_state) +{ + global $user; + /************************ start approve book details ************************/ + if ($user->uid == 0) + { + $msg = drupal_set_message(t('It is mandatory to ' . l('login', 'user') . ' on this website to access the case study proposal form. If you are new user please create a new account first.'), 'error'); + drupal_goto('user'); + return $msg; + } //$user->uid == 0 + $form['#attributes'] = array( + 'enctype' => "multipart/form-data" + ); + $form['new_project_title_name'] = array( + '#type' => 'textfield', + '#title' => t('Enter the name of the project title'), + '#size' => 250, + '#attributes' => array( + 'placeholder' => t('Enter the name of the project title displayed to the contributor') + ), + '#maxlength' => 250, + '#required' => TRUE + ); + $form['upload_project_title_resource_file'] = array( + '#type' => 'fieldset', + '#title' => t('Browse and upload the file to display with the project title'), + '#collapsible' => FALSE, + '#collapsed' => FALSE + ); + $form['upload_project_title_resource_file']['project_title_resource_file_path'] = array( + '#type' => 'file', + '#size' => 48, + '#description' => t('<span style="color:red;">Upload filenames with allowed extensions only. No spaces or any special characters allowed in filename.</span>') . '<br />' . t('<span style="color:red;">Allowed file extensions: ') . variable_get('list_of_available_projects_file', '') . '</span>' + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); + return $form; +} +function add_project_title_form_validate($form, &$form_state) { + if (isset($_FILES['files'])) + { + /* check if atleast one source or result file is uploaded */ + if (!($_FILES['files']['name']['project_title_resource_file_path'])) + form_set_error('project_title_resource_file_path', t('Please upload the file')); + /* check for valid filename extensions */ + foreach ($_FILES['files']['name'] as $file_form_name => $file_name) + { + if ($file_name) + { + /* checking file type */ + $allowed_extensions_str = variable_get('list_of_available_projects_file', ''); + $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 (!cfd_case_study_check_valid_filename($_FILES['files']['name'][$file_form_name])) + form_set_error($file_form_name, t('Invalid file name specified. Only alphabets and numbers are allowed as a valid filename.')); + } //$file_name + } //$_FILES['files']['name'] as $file_form_name => $file_name + } + return $form_state; +} + +function add_project_title_form_submit($form, &$form_state) { + global $user; + $v = $form_state["values"]; + $result = "INSERT INTO {list_of_project_titles} + ( + project_title_name + )VALUES + ( + :project_title_name + )"; + $args = array( + ":project_title_name" => $v['new_project_title_name'] + ); + $result1 = db_query($result, $args, array( + 'return' => Database::RETURN_INSERT_ID + )); + $dest_path = cfd_case_study_project_titles_resource_file_path(); + foreach ($_FILES['files']['name'] as $file_form_name => $file_name) + { + if ($file_name) + { + /* checking file type */ + //$file_type = 'S'; + //var_dump($dest_path . $result1 .'_' . $_FILES['files']['name'][$file_form_name]);die; + if (file_exists($dest_path . $result1 . '_' . $_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], $dest_path . $result1 . '_' . $_FILES['files']['name'][$file_form_name])) + { + $query = "UPDATE {list_of_project_titles} SET filepath = :filepath WHERE id = :id"; + $args = array( + ":filepath" => $result1 . '_' . $_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 + drupal_set_message(t('Project title added successfully'), 'status'); +}
\ No newline at end of file diff --git a/available_project_titles_list.inc b/available_project_titles_list.inc new file mode 100644 index 0000000..0787856 --- /dev/null +++ b/available_project_titles_list.inc @@ -0,0 +1,33 @@ +<?php +// case study display completed proposals +function list_of_available_project_titles() +{ + $output = ""; + $static_url = "https://static.fossee.in/cfd/project-titles/"; + $preference_rows = array(); + $i = 1; + $query = db_query("SELECT * from list_of_project_titles WHERE {project_title_name} NOT IN( SELECT project_title from case_study_proposal WHERE approval_status = 0 OR approval_status = 1 OR approval_status = 3)"); + while($result = $query->fetchObject()) { + $preference_rows[] = array( + $i, + //print_r(array_keys($case_studies_list)) + l($result->project_title_name, $static_url . $result->filepath, array( + 'external' => TRUE, + 'attributes' => array( + 'target'=> '_blank', + ), + )) + ); + $i++; + } + $preference_header = array( + 'No', + 'List of available projects' + ); + $output .= theme('table', array( + 'header' => $preference_header, + 'rows' => $preference_rows + )); + + return $output; +}
\ No newline at end of file diff --git a/cfd_case_study.module b/cfd_case_study.module index 431b5af..576a8d7 100755 --- a/cfd_case_study.module +++ b/cfd_case_study.module @@ -1,5 +1,8 @@ <?php // $Id$ +/*error_reporting(E_ALL); +ini_set('display_errors', TRUE); +ini_set('display_startup_errors', TRUE);*/ require_once('general_deletion.inc'); require_once('email.inc'); /** @@ -9,6 +12,19 @@ function cfd_case_study_menu() { $items = array(); /* PROPOSAL */ + $items['case-study-project/add-project-title'] = array( + 'title'=> 'Add new project titles', + 'description'=> 'Add new project titles', + 'page callback'=> 'drupal_get_form', + 'page arguments'=> array( + 'add_project_title_form' + ), + 'access arguments'=> array( + 'Case Study add project titles' + ), + 'type'=> MENU_NORMAL_ITEM, + 'file'=> 'add_project_titles.inc' + ); $items['case-study-project/proposal'] = array( 'title'=> 'Case Study Proposal Form', 'description'=> 'Case Study Proposal Form', @@ -175,6 +191,14 @@ function cfd_case_study_menu() ), 'file'=> 'cfd_case_study_details.inc' ); + $items['case-study-project/list-of-project-titles'] = array( + 'title'=> 'List of available Project titles', + 'page callback'=> 'list_of_available_project_titles', + 'access arguments'=> array( + 'Case Study Project titles list' + ), + 'file'=> 'available_project_titles_list.inc' + ); /* DOWNLOAD FOR EVERYONE */ $items['case-study-project/case-study-run'] = array( 'title'=> 'Download Codes', @@ -287,6 +311,10 @@ function cfd_case_study_menu() function cfd_case_study_permission() { return array( + 'Case Study add project titles'=> array( + 'title'=> t('Case Study add project titles'), + 'restrict access'=> TRUE + ), 'Case Study create proposal'=> array( 'title'=> t('Case Study create proposal'), 'restrict access'=> TRUE @@ -307,6 +335,10 @@ function cfd_case_study_permission() 'title'=> t('Case Study propose solution'), 'restrict access'=> TRUE ), + 'Case Study Project titles list'=> array( + 'title'=> t('Case Study Project titles list'), + 'restrict access'=> TRUE + ), 'Case Study approve abstract'=> array( 'title'=> t('Case Study approve code'), 'restrict access'=> TRUE @@ -385,6 +417,9 @@ function cfd_case_study_file_path($value='') { return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'cfd_uploads/'; } +function cfd_case_study_project_titles_resource_file_path() { + return $_SERVER['DOCUMENT_ROOT'] . '/SiteFiles/cfd/project-titles/'; +} /************************* USER VERIFICATION FUNCTIONS ************************/ function cfd_case_study_get_proposal() { @@ -511,6 +546,18 @@ function _df_list_of_departments() } //$department_list_data = $department_list->fetchObject() return $department; } + +function _cs_list_of_case_studies() +{ + $existing_case_studies = array(); + $result = db_query("SELECT * from list_of_project_titles WHERE {project_title_name} NOT IN( SELECT project_title from case_study_proposal WHERE approval_status = 0 OR approval_status = 1 OR approval_status = 3)"); + while ($case_study_list_data = $result->fetchObject()) + { + $existing_case_studies[$case_study_list_data->project_title_name] = $case_study_list_data->project_title_name; + } + return $existing_case_studies; +} + function _df_dir_name($project, $proposar_name) { $project_title = ucname($project); diff --git a/cfd_case_study_details.inc b/cfd_case_study_details.inc index 89a5645..c9c6099 100755 --- a/cfd_case_study_details.inc +++ b/cfd_case_study_details.inc @@ -1,5 +1,5 @@ <?php -// eSim case study display completed proposals +// case study display completed proposals function cfd_case_study_completed_proposals_all() { $output = ""; diff --git a/proposal.inc b/proposal.inc index ba174a3..c1beb27 100755 --- a/proposal.inc +++ b/proposal.inc @@ -199,13 +199,51 @@ function cfd_case_study_proposal_form($form, &$form_state, $no_js_use = FALSE) '#type' => 'item', '#markup' => '<hr>' ); + $form['cfd_project_title_check'] = array( + '#type' => 'radios', + '#title' => t('Is the proposed CFD Case study from the list of available CFD Case studies?'), + '#options' => array( + '1' => 'Yes', + '0' => 'No', + ), + '#validated' => TRUE, + ); + $form['cfd_case_study_name_dropdown'] = array( + '#type' => 'select', + '#title' => t('Select the name of available cfd'), + '#required' => TRUE, + '#options' => _cs_list_of_case_studies(), + '#validated' => TRUE, + '#states' => array( + 'visible' => array( + ':input[name="cfd_project_title_check"]' => array( + 'value' => '1' + ) + ) + ), + ); $form['project_title'] = array( + '#type' => 'textarea', + '#title' => t('Project Title'), + '#size' => 250, + '#description' => t('Maximum character limit is 250'), + '#required' => TRUE, + '#validated' => TRUE, + '#states' => array( + 'visible' => array( + ':input[name="cfd_project_title_check"]' => array( + 'value' => '0' + ) + ) + ), + ); + /*$form['project_title'] = array( '#type' => 'textfield', '#title' => t('Project Title'), '#size' => 250, '#description' => t('Maximum character limit is 250'), '#required' => TRUE - ); + );*/ $form['solver_used'] = array( '#type' => 'textfield', '#title' => t('Solver to be used'), @@ -260,6 +298,14 @@ function cfd_case_study_proposal_form($form, &$form_state, $no_js_use = FALSE) } function cfd_case_study_proposal_form_validate($form, &$form_state) { + if($form_state['values']['cfd_project_title_check'] == 1) + { + $project_title = $form_state['values']['cfd_case_study_name_dropdown']; + } + else{ + + $project_title = $form_state['values']['project_title']; + } if ($form_state['values']['term_condition'] == '1') { form_set_error('term_condition', t('Please check the terms and conditions')); @@ -326,10 +372,10 @@ function cfd_case_study_proposal_form_validate($form, &$form_state) 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 + /*else { form_set_error('project_title', t('Project title shoud not be empty')); - } + }*/ if ($form_state['values']['solver_used'] != '') { if (strlen($form_state['values']['solver_used']) > 50) @@ -386,9 +432,17 @@ function cfd_case_study_proposal_form_submit($form, &$form_state) drupal_set_message('It is mandatory to login on this website to access the proposal form', 'error'); return; } + if($form_state['values']['cfd_project_title_check'] == 1) + { + $project_title = $form_state['values']['cfd_case_study_name_dropdown']; + } + else{ + + $project_title = $form_state['values']['project_title']; + } /* inserting the user proposal */ $v = $form_state["values"]; - $project_title = trim($v['project_title']); + $project_title = trim($project_title); $proposar_name = $v['name_title'] . ' ' . $v['contributor_name']; $university = $v['university']; $directory_name = _df_dir_name($project_title, $proposar_name); @@ -449,7 +503,7 @@ function cfd_case_study_proposal_form_submit($form, &$form_state) ":pincode" => $v['pincode'], ":state" => $v['all_state'], ":country" => $v['country'], - ":project_title" => $v['project_title'], + ":project_title" => $project_title, ":solver_used" => $v['solver_used'], ":directory_name" => $directory_name, ":approval_status" => 0, diff --git a/settings.inc b/settings.inc index 010f8e1..0586bdd 100755 --- a/settings.inc +++ b/settings.inc @@ -56,6 +56,15 @@ function cfd_case_study_settings_form($form, $form_state) '#required' => TRUE, '#default_value' => variable_get('case_study_project_files_extensions', '') ); + $form['extensions']['list_of_available_projects_file'] = array( + '#type' => 'textfield', + '#title' => t('Allowed file extensions for file uploaded for available projects list'), + '#description' => t('A comma separated list WITHOUT SPACE of file extensions that are permitted to be uploaded on the server'), + '#size' => 50, + '#maxlength' => 255, + '#required' => TRUE, + '#default_value' => variable_get('list_of_available_projects_file', '') + ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit') @@ -74,5 +83,6 @@ function cfd_case_study_settings_form_submit($form, &$form_state) variable_set('resource_upload_extensions', $form_state['values']['resource_upload']); variable_set('case_study_abstract_upload_extensions', $form_state['values']['abstract_upload']); variable_set('case_study_project_files_extensions', $form_state['values']['case_study_upload']); + variable_set('list_of_available_projects_file', $form_state['values']['list_of_available_projects_file']); drupal_set_message(t('Settings updated'), 'status'); } |