diff options
-rwxr-xr-x | arduino_projects_blog.module | 219 | ||||
-rwxr-xr-x | code.inc | 819 | ||||
-rwxr-xr-x | code_approval.inc | 1223 | ||||
-rwxr-xr-x | download.inc | 177 | ||||
-rwxr-xr-x | editstep.inc | 1043 | ||||
-rwxr-xr-x | email.inc | 5 | ||||
-rwxr-xr-x | manage_proposal.inc | 31 | ||||
-rw-r--r-- | my_proposals.inc | 2 | ||||
-rwxr-xr-x | proposal.inc | 11 | ||||
-rwxr-xr-x | settings.inc | 17 | ||||
-rwxr-xr-x | upload_project.inc | 543 |
11 files changed, 3965 insertions, 125 deletions
diff --git a/arduino_projects_blog.module b/arduino_projects_blog.module index 76acdb1..744829e 100755 --- a/arduino_projects_blog.module +++ b/arduino_projects_blog.module @@ -1,8 +1,8 @@ <?php // $Id$ -/*error_reporting(E_ALL); +error_reporting(E_ALL); ini_set('display_errors', TRUE); -ini_set('display_startup_errors', TRUE);*/ +ini_set('display_startup_errors', TRUE); require_once('general_deletion.inc'); require_once('email.inc'); /** @@ -134,44 +134,115 @@ function arduino_projects_blog_menu() 'type' => MENU_CALLBACK, 'file' => 'manage_proposal.inc' ); - $items['arduino-projects/abstract-approval/bulk'] = array( - 'title' => 'Bulk Manage', - 'description' => 'Bulk Mangage', + /* Final project Submission*/ + $items['arduino-projects/code'] = array( + 'title' => 'Project Submission', + 'description' => 'Project Submission', + 'page callback' => 'list_steps', + 'access callback' => 'user_access', + 'access arguments' => array( + 'arduino projects upload code' + ), + 'file' => 'upload_project.inc' + ); + $items['arduino-projects/code/list-steps'] = array( + 'title' => 'List Steps', + 'description' => 'List Steps', + 'page callback' => 'list_steps', + 'access arguments' => array( + 'arduino projects upload code' + ), + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'file' => 'upload_project.inc', + 'weight' => 1 + ); + $items['arduino-projects/code/view-step'] = array( + 'title' => 'View Step', + 'description' => 'View Step', + 'page callback' => 'view_steps', + 'access arguments' => array( + 'arduino projects upload code' + ), + 'type' => MENU_CALLBACK, + 'file' => 'upload_project.inc', + 'weight' => 3 + ); + $items['arduino-projects/code/step/edit'] = array( + 'title' => 'Edit Step', + 'description' => 'Edit Step', 'page callback' => 'drupal_get_form', 'page arguments' => array( - 'arduino_projects_blog_abstract_bulk_approval_form' + 'upload_step_edit_form' ), 'access arguments' => array( - 'arduino projects bulk manage abstract' + 'arduino projects edit uploaded step' + ), + 'type' => MENU_CALLBACK, + 'file' => 'editstep.inc' + ); + $items['arduino-projects/code/upload'] = array( + 'title' => 'Project Submission', + 'description' => 'Project Submission', + 'page callback' => 'upload_examples', + 'access arguments' => array( + 'arduino projects upload code' ), 'type' => MENU_LOCAL_TASK, - 'weight' => 2, - 'file' => 'abstract_bulk_approval.inc' + 'file' => 'code.inc', + 'weight' => 3 ); - /* CODE UPLOAD */ - $items['arduino-projects/abstract-code'] = array( - 'title' => 'Abstract and Arduino Projects Submission', - 'description' => 'Abstract Submission', - 'page callback' => 'arduino_projects_blog_abstract', - 'access callback' => 'user_access', + $items['arduino-projects/code/update-introduction'] = array( + 'title' => 'Introduction', + 'description' => 'Introduction', + 'page callback' => 'update_introduction', 'access arguments' => array( 'arduino projects upload code' ), - 'file' => 'upload_code.inc' + 'type' => MENU_LOCAL_TASK, + 'file' => 'upload_project.inc', + 'weight' => 2 ); - $items['arduino-projects/abstract-code/upload'] = array( - 'title' => 'Abstract and Arduino Projects Submission', - 'description' => 'Abstract Submission', + $items['arduino-projects/code-approval/step'] = array( + 'title' => 'Step approval form', + 'description' => 'Step approval form', 'page callback' => 'drupal_get_form', 'page arguments' => array( - 'arduino_projects_blog_upload_abstract_code_form' + 'step_approval_form' ), 'access arguments' => array( - 'arduino projects upload code' + 'arduino projects bulk manage code' + ), + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'weight' => 1, + 'file' => 'code_approval.inc' + ); + $items['arduino-projects/code-approval/bulk'] = array( + 'title' => 'Bulk Manage', + 'description' => 'Bulk Manage', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'bulk_approval_form' + ), + 'access arguments' => array( + 'arduino projects bulk manage code' ), 'type' => MENU_LOCAL_TASK, - 'file' => 'upload_code.inc', - 'weight' => 2 + 'weight' => 2, + 'file' => 'code_approval.inc' + ); + $items['arduino-projects/abstract-approval/bulk'] = array( + 'title' => 'Bulk Manage', + 'description' => 'Bulk Mangage', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'arduino_projects_blog_abstract_bulk_approval_form' + ), + 'access arguments' => array( + 'arduino projects bulk manage abstract' + ), + 'type' => MENU_LOCAL_TASK, + 'weight' => 2, + 'file' => 'abstract_bulk_approval.inc' ); /* CODE DOWNLOADS */ $items['arduino-projects/download/reference-images'] = array( @@ -184,6 +255,26 @@ function arduino_projects_blog_menu() 'type' => MENU_CALLBACK, 'file' => 'download.inc' ); + $items['arduino-projects/download/step-images'] = array( + 'title' => 'Download Step Images', + 'description' => 'Download Step Images', + 'page callback' => 'arduino_projects_blog_download_step_images', + 'access arguments' => array( + 'arduino projects download step files' + ), + 'type' => MENU_CALLBACK, + 'file' => 'download.inc' + ); + $items['arduino-projects/download/step-gifs'] = array( + 'title' => 'Download Step Gifs', + 'description' => 'Download Step Gifs', + 'page callback' => 'arduino_projects_blog_download_step_gifs', + 'access arguments' => array( + 'arduino projects download step files' + ), + 'type' => MENU_CALLBACK, + 'file' => 'download.inc' + ); $items['arduino-projects/download/abstract-file'] = array( 'title' => 'Download abstract file', 'description' => 'Download abstract file', @@ -214,24 +305,6 @@ function arduino_projects_blog_menu() 'type' => MENU_CALLBACK, 'file' => 'full_download.inc' ); - /* COMPLETED arduino projectsS */ - $items['arduino-projects/completed-pssp'] = array( - 'title' => 'Completed Arduino Projectss', - 'page callback' => 'arduino_projects_blog_completed_proposals_all', - 'access arguments' => array( - 'arduino projects download code' - ), - 'file' => 'pssp_details.inc' - ); - /* LABS IN PROGRESS */ - $items['arduino-projects/pssp-progress'] = array( - 'title' => 'Arduino Projectss in Progress', - 'page callback' => 'arduino_projects_blog_progress_all', - 'access arguments' => array( - 'arduino projects download code' - ), - 'file' => 'pssp_details.inc' - ); /* DOWNLOAD FOR EVERYONE */ $items['arduino-projects/arduino-projects-run'] = array( 'title' => 'Download Codes', @@ -313,8 +386,10 @@ function arduino_projects_blog_menu() 'type' => MENU_CALLBACK, 'file' => 'pdf/verify_certificates.inc' ); + return $items; } + /** * Implementation of hook_perm(). */ @@ -349,6 +424,10 @@ function arduino_projects_blog_permission() 'title' => t('arduino projects approve proposal'), 'restrict access' => TRUE ), + 'arduino projects edit uploaded step' => array( + 'title' => t('arduino projects edit uploaded step'), + 'restrict access' => TRUE + ), 'arduino projects propose solution' => array( 'title' => t('arduino projects propose solution'), 'restrict access' => TRUE @@ -357,6 +436,10 @@ function arduino_projects_blog_permission() 'title' => t('arduino projects approve code'), 'restrict access' => TRUE ), + 'arduino projects bulk manage code' => array( + 'title' => t('arduino projects bulk manage code'), + 'restrict access' => TRUE + ), 'arduino projects bulk manage abstract' => array( 'title' => t('arduino projects bulk manage abstract'), 'restrict access' => TRUE @@ -377,6 +460,10 @@ function arduino_projects_blog_permission() 'title' => t('arduino projects download reference images'), 'restrict access' =>TRUE ), + 'arduino projects download step files' => array( + 'title' => t('arduino projects download step files'), + 'restrict access' =>TRUE + ), 'administer arduino projects' => array( 'title' => t('administer arduino projects'), 'restrict access' => TRUE @@ -418,13 +505,7 @@ function arduino_projects_blog_check_name($name = '') else return TRUE; } -function arduino_projects_blog_check_code_number($number = '') -{ - if (!preg_match('/^[0-9]+$/', $number)) - return FALSE; - else - return TRUE; -} + /************************* USER VERIFICATION FUNCTIONS ************************/ function arduino_projects_blog_get_proposal() { @@ -568,6 +649,48 @@ function _df_list_of_departments() } //$department_list_data = $department_list->fetchObject() return $department; } +function generateVideoEmbedUrl($url){ + //This is a general function for generating an embed link of an FB/Vimeo/Youtube Video. + $finalUrl = ''; + if(strpos($url, 'facebook.com/') !== false) { + //it is FB video + $finalUrl.='https://www.facebook.com/plugins/video.php?href='.rawurlencode($url).'&show_text=1&width=200'; + }else if(strpos($url, 'vimeo.com/') !== false) { + //it is Vimeo video + $videoId = explode("vimeo.com/",$url)[1]; + if(strpos($videoId, '&') !== false){ + $videoId = explode("&",$videoId)[0]; + } + $finalUrl.='https://player.vimeo.com/video/'.$videoId; + }else if(strpos($url, 'youtube.com/') !== false) { + //it is Youtube video + $videoId = explode("v=",$url)[1]; + if(strpos($videoId, '&') !== false){ + $videoId = explode("&",$videoId)[0]; + } + $finalUrl.='https://www.youtube.com/embed/'.$videoId; + }else if(strpos($url, 'youtu.be/') !== false){ + //it is Youtube video + $videoId = explode("youtu.be/",$url)[1]; + if(strpos($videoId, '&') !== false){ + $videoId = explode("&",$videoId)[0]; + } + $finalUrl.='https://www.youtube.com/embed/'.$videoId; + }else{ + //Enter valid video URL + } + return $finalUrl; +} +function convertLinkToEmbed($videoLink, $width, $height) + { + $embed = ''; + if (preg_match('/https:\/\/(?:www.)?(youtube).com\/watch\\?v=(.*?)/', $videoLink)) + $embed = preg_replace("/\s*[a-zA-Z\/\/:\.]*youtube.com\/watch\?v=([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i", "<iframe width=\"" . $width . "\" height=\"" . $height . "\" src=\"//www.youtube.com/embed/$1\" frameborder=\"0\" allowfullscreen></iframe>", $videoLink); + if (preg_match('/https:\/\/vimeo.com\/(\\d+)/', $videoLink, $regs)) + $embed = '<iframe src="http://player.vimeo.com/video/' . $regs[1] . '?title=0&byline=0&portrait=0&badge=0&color=ffffff" width="' . $width . '" height="' . $height . '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>'; + return $embed; + + } function _apb_dir_name($project, $proposar_name) { diff --git a/code.inc b/code.inc new file mode 100755 index 0000000..d9919d6 --- /dev/null +++ b/code.inc @@ -0,0 +1,819 @@ +<?php +// $Id$ +function upload_examples() + { + return drupal_get_form('upload_examples_form'); + } +function upload_examples_form($form, &$form_state, $no_js_use = FALSE) + { + global $user; + /************************ start approve book details ************************/ + /*$proposal_q = db_query("SELECT * FROM {arduino_projects_blog_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid); + $proposal_data = db_fetch_object($proposal_q);*/ + $query = db_select('arduino_projects_blog_proposal'); + $query->fields('arduino_projects_blog_proposal'); + $query->condition('uid', $user->uid); + $query->orderBy('id', 'DESC'); + $query->range(0, 1); + $result = $query->execute(); + $proposal_data = $result->fetchObject(); + if (!$proposal_data) + { + drupal_set_message("Please submit a " . l('proposal', 'textbook-companion/proposal') . ".", 'error'); + drupal_goto(''); + } + if ($proposal_data->approval_status != 1 && $proposal_data->approval_status != 4) + { + switch ($proposal_data->approval_status) + { + case 0: + drupal_set_message(t('We have already received your proposal. We will get back to you soon.'), 'status'); + drupal_goto(''); + return; + break; + case 2: + drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'textbook-companion/proposal') . '.'), 'error'); + drupal_goto(''); + return; + break; + case 3: + drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'textbook-companion/proposal') . '.'), 'status'); + drupal_goto(''); + return; + break; +case 5: + drupal_set_message(t('You have submitted your all codes.'), 'status'); + drupal_goto(''); + return; + default: + drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error'); + drupal_goto(''); + return; + break; + } + } + /*$preference_q = db_query("SELECT * FROM {arduino_projects_blog_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id); + $proposal_data = db_fetch_object($preference_q);*/ + + if (!$proposal_data) + { + drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error'); + drupal_goto(''); + return; + } + $form['#attributes'] = array( + 'enctype' => "multipart/form-data" + ); +$form['proposal_id'] = array( + '#type' => 'hidden', + '#value' => $proposal_data->id, + ); + $form['project_title'] = array( + '#type' => 'item', + '#markup' => $proposal_data->project_title, + '#title' => t('Title of the Project') + ); + $form['contributor_name'] = array( + '#type' => 'item', + '#markup' => $proposal_data->contributor_name, + '#title' => t('Contributor Name') + ); + $query = db_select('arduino_projects_blog_step'); + $query->fields('arduino_projects_blog_step'); + $query->condition('proposal_id', $proposal_data->id); + //$query->condition('approval_status', 1); + //$query->range(0, 1); + $step_numbers = array(); + $result = $query->execute(); + //$i = 1; + while ($step_data = $result->fetchObject()){ + $step_numbers[$step_data->number] = $step_data->number; + } + $options = array( + '' => '(Select)' + ); + for ($i = 1; $i <= 100; $i++) + { + $options[$i] = $i; + } + $step_options = array_diff($options, $step_numbers); + $form['number'] = array( + '#type' => 'select', + '#title' => t('Step No'), + '#options' => $step_options, + '#multiple' => FALSE, + '#size' => 1, + '#required' => TRUE, + '#ajax' => array( + 'callback' => 'ajax_step_name_callback', + ), + ); + $number = isset($form_state['values']['number']) ? $form_state['values']['number'] : key($options); + $query = db_select('arduino_projects_blog_step_titles'); + $query->fields('arduino_projects_blog_step_titles'); + $query->condition('step_no', $number); + $result = $query->execute(); + $step_data = $result->fetchObject(); + $form['name'] = array( + '#type' => 'textfield', + '#title' => t('Title of the Step'), + '#size' => 40, + '#maxlength' => 255, + '#required' => TRUE, + '#prefix' => '<div id="ajax-step-name-replace">', + '#suffix' => '</div>', + ); + $form['description'] = array( + '#type' => 'text_format', + '#title' => t('Description'), + '#required' => TRUE + ); + $form['step_images'] = array( + '#type' => 'fieldset', + '#tree' => TRUE, + '#prefix' => '<div id="names-fieldset-wrapper">', + '#suffix' => '</div>', + '#title' => t('Upload images related to the step'), + ); + if (empty($form_state['image_names'])) { + $form_state['image_names'] = 1; + } + for ($i = 0; $i < $form_state['image_names']; $i++) { + $temp_no = $i; + $form['step_images'][$i]['image'] = array( + //'#title' => t('Add Event Image'), + '#type' => 'file', + '#weight' => '5', + '#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('step_image_extensions', '') . t('</span>'), + // We need this to know which file element this is. + // By default drupal would name all as files[step_images] + '#name' => 'files[step_images_' . $i . '_name]', + //'#attributes' => array('multiple' => 'multiple'), + //'#upload_location' => 'public://', + '#upload_validators' => array( + // Pass the maximum file size in bytes + 'file_validate_size' => array(2*1024), + ), + ); + $form['step_images']["images_count"] = array( + "#type" => "hidden", + "#value" => $temp_no + ); + } + if($i < 5){ + $form['step_images']['add_image'] = array( + '#type' => 'submit', + '#value' => t('Add Image'), + '#limit_validation_errors' => array(), + '#submit' => array( + 'step_images_add_more_add_one' + ), + '#ajax' => array( + 'callback' => 'step_images_add_more_callback', + 'wrapper' => 'names-fieldset-wrapper' + ) + ); + } + if ($form_state['image_names'] > 1) { + $form['step_images']['remove_image'] = array( + '#type' => 'submit', + '#value' => t('Remove Image'), + '#limit_validation_errors' => array(), + '#submit' => array( + 'step_images_add_more_remove_one' + ), + '#ajax' => array( + 'callback' => 'step_images_add_more_callback', + 'wrapper' => 'names-fieldset-wrapper' + ) + ); + } + if ($no_js_use) { + if (!empty($form['step_images']['remove_image']['#ajax'])) { + unset($form['step_images']['remove_image']['#ajax']); + } + unset($form['step_images']['add_image']['#ajax']); + } + $form['step_video'] = array( + '#type' => 'textarea', + '#title' => t('Upload Video related to the step'), + '#size' => 600, + '#maxlength' => 600, + ); + $form['step_gifs'] = array( + '#type' => 'fieldset', + '#tree' => TRUE, + '#prefix' => '<div id="gifs-fieldset-wrapper">', + '#suffix' => '</div>', + '#title' => t('Upload gifs related to the step'), + ); + if (empty($form_state['gif_names'])) { + $form_state['gif_names'] = 1; + } + for ($p = 0; $p < $form_state['gif_names']; $p++) { + $temp_no = $p; + $form['step_gifs'][$p]['gifs'] = array( + //'#title' => t('Add Event Image'), + '#type' => 'file', + '#weight' => '5', + '#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: gif</span>'), + // We need this to know which file element this is. + // By default drupal would name all as files[step_gifs] + '#name' => 'files[step_gifs_' . $p . '_name]', + //'#attributes' => array('multiple' => 'multiple'), + //'#upload_location' => 'public://', + '#upload_validators' => array( + 'file_validate_extensions' => ['gif'], + // Pass the maximum file size in bytes + 'file_validate_size' => array(2*1024), + ), + ); + $form['step_gifs']["images_count"] = array( + "#type" => "hidden", + "#value" => $temp_no + ); + } + if($p < 5){ + $form['step_gifs']['add_gif'] = array( + '#type' => 'submit', + '#value' => t('Add Gif'), + '#limit_validation_errors' => array(), + '#submit' => array( + 'step_gifs_add_more_add_one' + ), + '#ajax' => array( + 'callback' => 'step_gifs_add_more_callback', + 'wrapper' => 'gifs-fieldset-wrapper' + ) + ); + } + if ($form_state['gif_names'] > 1) { + $form['step_gifs']['remove_gif'] = array( + '#type' => 'submit', + '#value' => t('Remove Gif'), + '#limit_validation_errors' => array(), + '#submit' => array( + 'step_gifs_add_more_remove_one' + ), + '#ajax' => array( + 'callback' => 'step_gifs_add_more_callback', + 'wrapper' => 'gifs-fieldset-wrapper' + ) + ); + } + if ($no_js_use) { + if (!empty($form['step_gifs']['remove_gif']['#ajax'])) { + unset($form['step_gifs']['remove_gif']['#ajax']); + } + unset($form['step_gifs']['add_gif']['#ajax']); + } + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); + $form['cancel'] = array( + '#type' => 'markup', + '#value' => l(t('Cancel'), 'textbook-companion/code') + ); + return $form; + } +function step_images_add_more_callback($form, $form_state) { + return $form['step_images']; +} + + +function step_images_add_more_add_one($form, &$form_state) { + $form_state['image_names']++; + $form_state['rebuild'] = TRUE; + //$form_state['no_redirect'] = TRUE; +} + + +function step_images_add_more_remove_one($form, &$form_state) { + if ($form_state['image_names'] > 1) { + $form_state['image_names']--; + } + $form_state['rebuild'] = TRUE; +} +function step_gifs_add_more_callback($form, $form_state) { + return $form['step_gifs']; +} + + +function step_gifs_add_more_add_one($form, &$form_state) { + $form_state['gif_names']++; + $form_state['rebuild'] = TRUE; + //$form_state['no_redirect'] = TRUE; +} + + +function step_gifs_add_more_remove_one($form, &$form_state) { + if ($form_state['gif_names'] > 1) { + $form_state['gif_names']--; + } + $form_state['rebuild'] = TRUE; +} + +function upload_examples_form_validate($form, &$form_state) + { + /*if (!arduino_projects_blog_check_name($form_state['values']['name'])) + form_set_error('name', t('Title of the Step can contain only alphabets, numbers and spaces.'));*/ + /* if (isset($_FILES['files'])) + { + + /* check if atleast one source or result file is uploaded */ + //if ($_FILES['files']['name']['sourcefile1'] || $_FILES['files']['name']['upload_dataset']) + // form_set_error('sourcefile1', t('Please upload source file.')); + /* check for valid filename extensions + foreach ($_FILES['files']['name'] as $file_form_name => $file_name) + { + if ($file_name) + { + if (strstr($file_form_name, 'image')) + $file_type = 'I'; + else if (strstr($file_form_name, 'gifs')) + $file_type = 'G'; + $allowed_extensions_str = ''; + switch ($file_type) + { + case 'I': + $allowed_extensions_str = variable_get('step_image_extensions', ''); + break; + case 'G': + $allowed_extensions_str = 'gif'; + break; + } + //$allowed_extensions_str = variable_get('arduino_projects_blog_source_extensions', ''); + $allowed_extensions = explode(',', $allowed_extensions_str); + $temp_ext = explode('.', strtolower($_FILES['files']['name'][$file_form_name])); + $temp_extension = end($temp_ext); + $temp_extension = substr($_FILES['files']['name'][$file_form_name], strripos($_FILES['files']['name'][$file_form_name], '.')); // get file name + //var_dump($temp_extension); die; + 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 (!arduino_projects_blog_check_valid_filename($_FILES['files']['name'][$file_form_name])) + form_set_error($file_form_name, t('Invalid file name specified. Only alphabets, numbers and underscore is allowed as a valid filename.')); + } + } + }*/ + } +function upload_examples_form_submit($form, &$form_state) + { + global $user; + $root_path = arduino_projects_blog_files_path(); + /************************ start approve book details ************************/ + /*$proposal_q = db_query("SELECT * FROM {arduino_projects_blog_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid); + $proposal_data = db_fetch_object($proposal_q);*/ + $query = db_select('arduino_projects_blog_proposal'); + $query->fields('arduino_projects_blog_proposal'); + $query->condition('uid', $user->uid); + $query->orderBy('id', 'DESC'); + $query->range(0, 1); + $result = $query->execute(); + $proposal_data = $result->fetchObject(); + if (!$proposal_data) + { + drupal_set_message("Please submit a " . l('proposal', 'textbook-companion/proposal') . ".", 'error'); + drupal_goto(''); + } + if ($proposal_data->approval_status != 1 && $proposal_data->approval_status != 4) + { + switch ($proposal_data->approval_status) + { + case 0: + drupal_set_message(t('We have already received your proposal. We will get back to you soon.'), 'status'); + drupal_goto(''); + return; + break; + case 2: + drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'textbook-companion/proposal') . '.'), 'error'); + drupal_goto(''); + return; + break; + case 3: + drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'textbook-companion/proposal') . '.'), 'status'); + drupal_goto(''); + return; + break; +case 5: + drupal_set_message(t('You have submmited your all codes'), 'status'); + drupal_goto(''); + return; + break; + default: + drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error'); + drupal_goto(''); + return; + break; + } + } + /*$preference_q = db_query("SELECT * FROM {arduino_projects_blog_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id); + $proposal_data = db_fetch_object($preference_q);*/ + $query = db_select('arduino_projects_blog_proposal'); + $query->fields('arduino_projects_blog_proposal'); + $query->condition('id', $proposal_data->id); + $query->condition('approval_status', 1); + $query->range(0, 1); + $result = $query->execute(); + $proposal_data = $result->fetchObject(); + if (!$proposal_data) + { + drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error'); + drupal_goto(''); + return; + } + /************************ end approve book details **************************/ + $proposal_directory = $proposal_data->directory_name; + $dest_path = $proposal_directory . '/'; + if (!is_dir($root_path . $dest_path)){ + if(!mkdir($root_path . $dest_path)) + { + drupal_set_message(t('You cannot upload your code. Error in creating directory'), 'error'); + } + } + /* inserting step details */ + $step_id = 0; + /*$step_result = db_query("SELECT * FROM {arduino_projects_blog_step} WHERE preference_id = %d AND number = %d", $preference_id, $form_state['values']['number']);*/ + + //var_dump($form_state['values']['name']);die; + $proposal_id = $proposal_data->id; + $query = db_select('arduino_projects_blog_step'); + $query->fields('arduino_projects_blog_step'); + $query->condition('proposal_id', $proposal_id); + $query->condition('number', $form_state['values']['number']); + $step_result = $query->execute(); + if (!$step_row = $step_result->fetchObject()) + { + $query = "INSERT INTO {arduino_projects_blog_step} (proposal_id, number, name) VALUES(:proposal_id, :number, :name)"; + $args = array( + ":proposal_id" => $proposal_id, + ":number" => $form_state['values']['number'], + ":name" => $form_state['values']['name'] + ); + $result = db_query($query, $args, array( + 'return' => Database::RETURN_INSERT_ID + )); + $step_id = $result; + } + else + { + $step_id = $step_row->id; + $query = db_update('arduino_projects_blog_step'); + $query->fields(array( + 'name' => $form_state['values']['name'] + )); + $query->condition('id', $step_id); + $num_updated = $query->execute(); + } + $query = db_select('arduino_projects_blog_step_information'); + $query->fields('arduino_projects_blog_step_information'); + $query->condition('step_id', $step_id); + $cur_example_q = $query->execute(); + if ($cur_example_d = $cur_example_q->fetchObject()) + { + if ($cur_example_d->approval_status == 1) + { + drupal_set_message(t("Example already approved. Cannot overwrite it."), 'error'); + drupal_goto('textbook-companion/code'); + return; + } + else if ($cur_example_d->approval_status == 0) + { + drupal_set_message(t("Example is under pending review. Delete the example and reupload it."), 'error'); + drupal_goto('textbook-companion/code'); + return; + } + else + { + drupal_set_message(t("Error uploading example. Please contact administrator."), 'error'); + drupal_goto('textbook-companion/code'); + return; + } + } + /* creating directories */ + $dest_path .= 'project_files/'; + if (!is_dir($root_path . $dest_path)) + mkdir($root_path . $dest_path); + $dest_path .= 'Step' . $form_state['values']['number'] . '/'; + if (!is_dir($root_path . $dest_path)) + mkdir($root_path . $dest_path); + $filepath = $proposal_directory . '/project_files/Step' . $form_state['values']['number'] . '/'; + $query = "INSERT INTO {arduino_projects_blog_step_information} (step_id, description, description_type, video, approval_date, approval_status, timestamp) VALUES (:step_id, :description, :description_type, :video, :approval_date,:approval_status, :timestamp)"; + $args = array( + ":step_id" => $step_id, + ":description" => $form_state['values']['description']['value'], + ":description_type" => $form_state['values']['description']['format'], + ":video" => $form_state['values']['step_video'], + ":approval_date" => time(), + ":approval_status" => 0, + ":timestamp" => time() + ); + $result = db_query($query, $args, array( + 'return' => Database::RETURN_INSERT_ID + )); + //$step_id = $result->step_id; + + foreach ($_FILES['files']['name'] as $file_form_name => $file_name) + { + if ($file_name) + { + /* checking file type */ + if (strstr($file_form_name, 'images')) + { + $file_type = 'I'; + } //strstr($file_form_name, 'upload_flowsheet_developed_process') + else if (strstr($file_form_name, 'gifs')) + { + $file_type = 'G'; + } + + //$file_type = 'S'; + switch ($file_type) { + case 'I': + $dest_path = $filepath . 'images/'; + //var_dump($root_path . $dest_path);die; + if (!is_dir($root_path . $dest_path)) + mkdir($root_path . $dest_path); + 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'); + return; + } + /* uploading file */ + else if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name])) + { + $query = "INSERT INTO {arduino_projects_blog_step_files} (step_id, filename, filepath,filemime, filesize, filetype, timestamp) + VALUES (:step_id, :filename ,:filepath,:filemime, :filesize, :filetype, :timestamp)"; + $args = array( + ":step_id" => $step_id, + ":filename" => $_FILES['files']['name'][$file_form_name], + ":filepath" => $dest_path . $_FILES['files']['name'][$file_form_name], + ":filemime" => mime_content_type($root_path . $dest_path . $_FILES['files']['name'][$file_form_name]), + ":filesize" => $_FILES['files']['size'][$file_form_name], + ":filetype" => $file_type, + ":timestamp" => time() + ); + $result = db_query($query, $args, array( + 'return' => Database::RETURN_INSERT_ID + )); + drupal_set_message($file_name . ' uploaded successfully.', 'status'); + } + else + { + drupal_set_message('Error uploading file : ' . $dest_path . $file_name, 'error'); + } + break; + case 'G': + $dest_path = $filepath . 'gifs/'; + //var_dump($root_path . $dest_path);die; + if (!is_dir($root_path . $dest_path)) + mkdir($root_path . $dest_path); + //var_dump($root_path . $dest_path);die; + 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'); + return; + } + /* uploading file */ + else if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name])) + { + $query = "INSERT INTO {arduino_projects_blog_step_files} (step_id, filename, filepath,filemime, filesize, filetype, timestamp) + VALUES (:step_id, :filename ,:filepath,:filemime, :filesize, :filetype, :timestamp)"; + $args = array( + ":step_id" => $step_id, + ":filename" => $_FILES['files']['name'][$file_form_name], + ":filepath" => $dest_path . $_FILES['files']['name'][$file_form_name], + ":filemime" => mime_content_type($root_path . $dest_path . $_FILES['files']['name'][$file_form_name]), + ":filesize" => $_FILES['files']['size'][$file_form_name], + ":filetype" => $file_type, + ":timestamp" => time() + ); + $result = db_query($query, $args, array( + 'return' => Database::RETURN_INSERT_ID + )); + drupal_set_message($file_name . ' uploaded successfully.', 'status'); + } + else + { + drupal_set_message('Error uploading file : ' . $dest_path . '/' . $file_name, 'error'); + } + break; + } + } + } + + drupal_set_message('Step uploaded successfully.', 'status'); + /* sending email */ + /*$email_to = $user->mail; + $from = variable_get('arduino_projects_blog_from_email', ''); + $bcc = variable_get('arduino_projects_blog_emails', ''); + $cc = variable_get('arduino_projects_blog_cc_emails', ''); + $params['example_uploaded']['example_id'] = $example_id; + $params['example_uploaded']['user_id'] = $user->uid; + $params['example_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('arduino_projects_blog', 'example_uploaded', $email_to, language_default(), $params, $from, TRUE)) + drupal_set_message('Error sending email message.', 'error');*/ + drupal_goto('arduino-projects/code'); + + + } +/******************************************************************************/ +/***************************** DELETE EXAMPLE *********************************/ +/******************************************************************************/ +function _upload_examples_delete() + { + global $user; + $root_path = arduino_projects_blog_path(); + $example_id = arg(3); + //var_dump($example_id);die; + /* check example */ + /*$example_q = db_query("SELECT * FROM {arduino_projects_blog_step_information} WHERE id = %d LIMIT 1", $example_id); + $example_data = db_fetch_object($example_q);*/ + $query = db_select('arduino_projects_blog_step_information'); + $query->fields('arduino_projects_blog_step_information'); + $query->condition('id', $example_id); + $query->range(0, 1); + $result = $query->execute(); + $example_data = $result->fetchObject(); + if (!$example_data) + { + drupal_set_message('Invalid example.', 'error'); + drupal_goto('textbook-companion/code'); + return; + } + if ($example_data->approval_status != 0) + { + drupal_set_message('You cannnot delete an example after it has been approved. Please contact site administrator if you want to delete this example.', 'error'); + drupal_goto('textbook-companion/code'); + return; + } + /*$step_q = db_query("SELECT * FROM {arduino_projects_blog_step} WHERE id = %d LIMIT 1", $example_data->step_id); + $step_data = db_fetch_object($step_q);*/ + $query = db_select('arduino_projects_blog_step'); + $query->fields('arduino_projects_blog_step'); + $query->condition('id', $example_data->step_id); + $query->range(0, 1); + $result = $query->execute(); + $step_data = $result->fetchObject(); + if (!$step_data) + { + drupal_set_message('You do not have permission to delete this example.', 'error'); + drupal_goto('textbook-companion/code'); + return; + } + /*$preference_q = db_query("SELECT * FROM {arduino_projects_blog_preference} WHERE id = %d LIMIT 1", $step_data->preference_id); + $proposal_data = db_fetch_object($preference_q);*/ + $query = db_select('arduino_projects_blog_preference'); + $query->fields('arduino_projects_blog_preference'); + $query->condition('id', $step_data->preference_id); + $query->range(0, 1); + $result = $query->execute(); + $proposal_data = $result->fetchObject(); + if (!$proposal_data) + { + drupal_set_message('You do not have permission to delete this example.', 'error'); + drupal_goto('textbook-companion/code'); + return; + } + /*$proposal_q = db_query("SELECT * FROM {arduino_projects_blog_proposal} WHERE id = %d AND uid = %d LIMIT 1", $proposal_data->proposal_id, $user->uid); + $proposal_data = db_fetch_object($proposal_q);*/ + $query = db_select('arduino_projects_blog_proposal'); + $query->fields('arduino_projects_blog_proposal'); + $query->condition('id', $proposal_data->proposal_id); + $query->condition('uid', $user->uid); + $query->range(0, 1); + $result = $query->execute(); + $proposal_data = $result->fetchObject(); + if (!$proposal_data) + { + drupal_set_message('You do not have permission to delete this example.', 'error'); + drupal_goto('textbook-companion/code'); + return; + } + /* deleting example files */ + if (delete_example($example_data->id)) + { + drupal_set_message('Example deleted.', 'status'); + /* sending email */ + + + $email_to = $user->mail; + $from = variable_get('arduino_projects_blog_from_email', ''); + $bcc = variable_get('arduino_projects_blog_emails', ''); + $cc = variable_get('arduino_projects_blog_cc_emails', ''); + $params['example_deleted_user']['book_title'] = $proposal_data->book; + $params['example_deleted_user']['step_title'] = $step_data->name; + $params['example_deleted_user']['example_number'] = $example_data->number; + $params['example_deleted_user']['example_caption'] = $example_data->caption; + $params['example_deleted_user']['user_id'] = $user->uid; + $params['example_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('arduino_projects_blog', 'example_deleted_user', $email_to, language_default(), $params, $from, TRUE)) + drupal_set_message('Error sending email message.', 'error'); + } + else + { + drupal_set_message('Error deleting example.', 'status'); + } + drupal_goto('textbook-companion/code'); + return; + } +/******************************************************************************/ +/************************** GENERAL FUNCTIONS *********************************/ +/******************************************************************************/ +function _list_of_book_titles() + { + $book_titles = array( + '0' => 'Please select...' + ); + /*$book_titles_q = db_query("SELECT * FROM {arduino_projects_blog_preference} WHERE approval_status = 1 OR approval_status = 3 ORDER BY book ASC");*/ + $query = db_select('arduino_projects_blog_preference'); + $query->fields('arduino_projects_blog_preference'); + $or = db_or(); + $or->condition('approval_status', 1); + $or->condition('approval_status', 3); + $query->condition($or); + $query->orderBy('book', 'ASC'); + $book_titles_q = $query->execute(); + while ($book_titles_data = $book_titles_q->fetchObject()) + { + $book_titles[$book_titles_data->id] = $book_titles_data->book . ' (Written by ' . $book_titles_data->author . ')'; + } + return $book_titles; + } +function _list_of_book_dependency_files() + { + $book_dependency_files = array(); + $book_dependency_files_class = array(); + /*$book_dependency_files_q = db_query("SELECT * FROM {arduino_projects_blog_dependency_files} ORDER BY filename ASC");*/ + $query = db_select('arduino_projects_blog_dependency_files'); + $query->fields('arduino_projects_blog_dependency_files'); + $query->orderBy('filename', 'ASC'); + $book_dependency_files_q = $query->execute(); + while ($book_dependency_files_data = $book_dependency_files_q->fetchObject()) + { + $temp_caption = ''; + if ($book_dependency_files_data->caption) + $temp_caption .= ' (' . $book_dependency_files_data->caption . ')'; + $book_dependency_files[$book_dependency_files_data->id] = l($book_dependency_files_data->filename . $temp_caption, 'download/dependency/' . $book_dependency_files_data->id, array( + 'attributes' => array( + 'class' => $book_dependency_files_data->preference_id + ) + )); + $book_dependency_files_class[$book_dependency_files_data->id] = $book_dependency_files_data->preference_id; + } + return array( + $book_dependency_files, + $book_dependency_files_class + ); + } + +function ajax_step_name_callback($form, $form_state){ + + $step_number = $form_state['values']['number']; + if($step_number <= 5){ + $query = "SELECT * FROM `arduino_projects_blog_step_titles` WHERE `step_no` = :number"; + $arg = array(':number' => $step_number); + $step_name_data = db_query($query, $arg); + + if ($step_name_data->rowCount() > 0) { + + //$form['name']['#default_value'] = $step_name_data->fetchObject()->name; + $form['name']['#value'] = $step_name_data->fetchObject()->step_title; + $form['name']['#readonly'] = TRUE; + $form['name']['#attributes']['readonly'] = 'readonly'; + $commands[] = ajax_command_replace("#ajax-step-name-replace", drupal_render($form['name'])); + + } + }else{ + $form['name']['#value'] = ' '; + $form['name']['#readonly'] = FALSE; + //$form['name']['#attributes']['readonly'] = 'readonly'; + $commands[] = ajax_command_replace("#ajax-step-name-replace", drupal_render($form['name'])); + + } + return array('#type' => 'ajax', '#commands' => $commands); + +}
\ No newline at end of file diff --git a/code_approval.inc b/code_approval.inc new file mode 100755 index 0000000..74f01d5 --- /dev/null +++ b/code_approval.inc @@ -0,0 +1,1223 @@ +<?php +/********************************* BULK APPROVAL ******************************/ +function step_approval_form($form, &$form_state) +{ + $options_first = _step_list_of_projects(); + $options_two = _ajax_bulk_get_step_list(); + $selected = isset($form_state['values']['project_title']) ? $form_state['values']['project_title'] : key($options_first); + $select_two = isset($form_state['values']['step']) ? $form_state['values']['step'] : key($options_two); + $form['project_title'] = array( + '#type' => 'select', + '#title' => t('Title of the Project'), + '#options' => _step_list_of_projects(), + '#default_value' => $selected, + '#tree' => TRUE, + '#ajax' => array( + 'callback' => 'ajax_bulk_step_list_callback' + ), + '#validated' => TRUE + ); + /*$form['book_actions'] = array( + '#type' => 'select', + '#title' => t('Please select action for selected book'), + '#options' => _bulk_list_book_actions(), + //'#default_value' => isset($form_state['values']['lab_actions']) ? $form_state['values']['lab_actions'] : 0, + '#prefix' => '<div id="ajax_selected_book_action" style="color:red;">', + '#suffix' => '</div>', + '#states' => array( + 'invisible' => array( + ':input[name="book"]' => array( + 'value' => 0 + ) + ) + ), + '#validated' => TRUE + );*/ + $form['step'] = array( + '#type' => 'select', + '#title' => t('Title of the Step'), + '#options' => _ajax_bulk_get_step_list($selected), + //'#default_value' => $chapter_default_value, + '#prefix' => '<div id="ajax_select_step_list">', + '#suffix' => '</div>', + '#validated' => TRUE, + '#tree' => TRUE, + '#ajax' => array( + 'callback' => 'ajax_bulk_step_details_list_callback' + ), + '#states' => array( + 'invisible' => array( + ':input[name="book"]' => array( + 'value' => 0 + ) + ) + ) + ); + $form['step_details'] = array( + '#type' => 'item', + '#prefix' => '<div id="ajax_selected_step"></div>' + ); + $form['step_actions'] = array( + '#type' => 'select', + '#title' => t('Please select action for selected step'), + '#options' => _bulk_list_step_actions(), + //'#default_value' => isset($form_state['values']['lab_actions']) ? $form_state['values']['lab_actions'] : 0, + '#prefix' => '<div id="ajax_selected_step_action" style="color:red;">', + '#suffix' => '</div>', + '#states' => array( + 'invisible' => array( + ':input[name="book"]' => array( + 'value' => 0 + ) + ) + ), + '#ajax' => array( + 'callback' => 'ajax_bulk_chapter_actions_callback' + ) + ); + /*$form['example'] = array( + '#type' => 'select', + '#title' => t('Example No. (Caption)'), + '#options' => _ajax_bulk_get_examples(), + // '#default_value' => $example_default_value, + '#validated' => TRUE, + '#prefix' => '<div id="ajax_selected_example">', + '#suffix' => '</div>', + '#states' => array( + 'invisible' => array( + ':input[name="book"]' => array( + 'value' => 0 + ) + ) + ), + '#ajax' => array( + 'callback' => 'ajax_bulk_example_files_callback' + ) + );*/ + /*$form['download_example'] = array( + '#type' => 'item', + '#markup' => '<div id="ajax_download_selected_example"></div>' + ); + $form['edit_example'] = array( + '#type' => 'item', + '#markup' => '<div id="ajax_edit_selected_example"></div>' + ); + $form['example_files'] = array( + '#type' => 'item', + '#markup' => '', + '#prefix' => '<div id="ajax_example_files_list">', + '#suffix' => '</div>' + ); + $form['example_actions'] = array( + '#type' => 'select', + '#title' => t('Please select action for selected example'), + '#options' => _bulk_list_example_actions(), + //'#default_value' => isset($form_state['values']['lab_actions']) ? $form_state['values']['lab_actions'] : 0, + '#prefix' => '<div id="ajax_selected_example_action" style="color:red;">', + '#suffix' => '</div>', + '#states' => array( + 'invisible' => array( + ':input[name="book"]' => array( + 'value' => 0 + ) + ) + ) + );*/ + $form['message'] = array( + '#type' => 'textarea', + '#title' => t('If Dis-Approved please specify reason for Dis-Approval'), + '#states' => array( + 'visible' => array( + array( + array( + ':input[name="step_actions"]' => array( + 'value' => 2 + ) + ), + 'or', + array( + ':input[name="step_actions"]' => array( + 'value' => 3 + ) + ), + ) + ), + 'required' => array( + array( + array( + ':input[name="step_actions"]' => array( + 'value' => 2 + ) + ), + 'or', + array( + ':input[name="step_actions"]' => array( + 'value' => 3 + ) + ), + ) + ) + ) + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit'), + '#states' => array( + 'invisible' => array( + ':input[name="project_title"]' => array( + 'value' => 0 + ) + ) + ) + ); + return $form; +} +function step_approval_form_submit($form, &$form_state) +{ + global $user; + $msg = ''; + $root_path = arduino_projects_blog_files_path(); + if ($form_state['clicked_button']['#value'] == 'Submit') + { + if ($form_state['values']['step']) + // om_pssp_abstract_del_lab_pdf($form_state['values']['om_pssp_project']); + if (user_access('arduino projects bulk manage code')) + { + $query = db_select('arduino_projects_blog_proposal'); + $query->fields('arduino_projects_blog_proposal'); + $query->condition('id', $form_state['values']['project_title']); + $user_query = $query->execute(); + $user_info = $user_query->fetchObject(); + $user_data = user_load($user_info->uid); + $steps_approved_count = $user_info->no_of_steps_approved; + $step_no = $form_state['values']['step']; + if ($form_state['values']['step_actions'] == 1) + { + // approving entire project // + $query = db_select('arduino_projects_blog_step'); + $query->fields('arduino_projects_blog_step'); + $query->condition('number', $form_state['values']['step']); + $result = $query->execute(); + $step_data = $result->fetchObject(); + $query = db_select('arduino_projects_blog_step_information'); + $query->fields('arduino_projects_blog_step_information'); + $query->condition('step_id', $step_data->id); + $abstracts_q = $query->execute(); + $experiment_list = ''; + while ($abstract_data = $abstracts_q->fetchObject()) + { + //var_dump($abstract_data);die; + db_query("UPDATE {arduino_projects_blog_step_information} SET approval_status = 1, approver_uid = :approver_uid, approval_date = :approval_date WHERE id = :id", array( + ':approver_uid' => $user->uid, + ':approval_date' => time(), + ':id' => $abstract_data->id + )); + db_query("UPDATE {arduino_projects_blog_step} SET approval_status = 1, approver_uid = :approver_uid, approval_date = :approval_date WHERE id = :id", array( + ':approver_uid' => $user->uid, + ':approval_date' => time(), + ':id' => $abstract_data->step_id + )); + db_query("UPDATE {arduino_projects_blog_proposal} SET no_of_steps_approved = :steps_approved WHERE id = :proposal_id", array( + ':steps_approved' => $steps_approved_count+1, + ':proposal_id' => $step_data->proposal_id + )); + } //$abstract_data = $abstracts_q->fetchObject() + drupal_set_message(t('Approved step no. ' . $step_data->number), 'status'); + // email + /*$email_subject = t('[!site_name][power system simulation Project] Your uploaded power system simulation project have been approved', array( + '!site_name' => variable_get('site_name', '') + )); + $email_body = array( + 0 => t(' + +Dear !user_name, + +Congratulations! +Your simulation and abstract for Power Systems Simulation Project at FOSSEE with the following details have been approved. + +Full Name: ' . $user_info->name_title . ' ' . $user_info->contributor_name . ' +Email : ' . $user_data->mail . ' +University/Institute : ' . $user_info->university . ' +City : ' . $user_info->city . ' + +Project Title : ' . $user_info->project_title . ' +Description of the simulation: ' . $user_info->description .' + +Kindly send us the internship forms as early as possible for processing your honorarium on time. In case you have already sent these forms, please share the the consignment number or tracking id with us. + +Note: It will take upto 30 days from the time we receive your forms, to process your honorarium. + + +Best Wishes, + +!site_name Power Systems 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('om_pssp_from_email', ''); + $bcc = variable_get('om_pssp_emails', ''); + $cc = variable_get('om_pssp_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('om_pssp', 'standard', $email_to, language_default(), $params, $from, TRUE)) + { + $msg = drupal_set_message('Error sending email message.', 'error'); + }*/ //!drupal_mail('om_pssp', 'standard', $email_to, language_default(), $params, $from, TRUE) + } //$form_state['values']['om_pssp_actions'] == 1 + elseif ($form_state['values']['step_actions'] == 2) + { + /*if (strlen(trim($form_state['values']['message'])) <= 30) + { + form_set_error('message', t('')); + $msg = drupal_set_message("Please mention the reason for marking resubmit. Minimum 30 character required", 'error'); + return $msg; + }*/ + //pending review entire project + + $query = db_select('arduino_projects_blog_step'); + $query->fields('arduino_projects_blog_step'); + $query->condition('number', $form_state['values']['step']); + $result = $query->execute(); + $step_data = $result->fetchObject(); + $query = db_select('arduino_projects_blog_step_information'); + $query->fields('arduino_projects_blog_step_information'); + $query->condition('step_id', $step_data->id); + $abstracts_q = $query->execute(); + $experiment_list = ''; + while ($abstract_data = $abstracts_q->fetchObject()) + { + db_query("UPDATE {arduino_projects_blog_step_information} SET approval_status = 0, approver_uid = :approver_uid, approval_date = :approval_date WHERE id = :id", array( + ':approver_uid' => $user->uid, + ':approval_date' => time(), + ':id' => $abstract_data->id + )); + db_query("UPDATE {arduino_projects_blog_step} SET approval_status = 0, approver_uid = :approver_uid, approval_date = :approval_date WHERE id = :id", array( + ':approver_uid' => $user->uid, + ':approval_date' => time(), + ':id' => $abstract_data->step_id + )); + db_query("UPDATE {arduino_projects_blog_proposal} SET submitted_steps = 0 WHERE id = :proposal_id", array( + ':proposal_id' => $step_data->proposal_id + )); + } //$abstract_data = $abstracts_q->fetchObject() + drupal_set_message(t('Resubmit the step files'), 'status'); + // email + /*$email_subject = t('[!site_name][power system simulation Project] Your uploaded power system simulation 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 . '. +Description of the simulation: ' . $user_info->description . ' + +Reason: ' . $form_state['values']['message'] . ' + +Looking forward for the re-submission from you with the above suggested changes. + +Best Wishes, + +!site_name Power Systems 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('om_pssp_from_email', ''); + $bcc = variable_get('om_pssp_emails', ''); + $cc = variable_get('om_pssp_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('om_pssp', 'standard', $email_to, language_default(), $params, $from, TRUE)) + { + drupal_set_message('Error sending email message.', 'error'); + } *///!drupal_mail('om_pssp', 'standard', $email_to, language_default(), $params, $from, TRUE) + } //$form_state['values']['om_pssp_actions'] == 2 + elseif ($form_state['values']['om_pssp_actions'] == 3) //disapprove and delete entire power system simulation 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('om pssp bulk delete code')) + { + $msg = drupal_set_message(t('You do not have permission to Bulk Dis-Approved and Deleted Entire Lab.'), 'error'); + return $msg; + } //!user_access('om_pssp bulk delete code') + if (om_pssp_abstract_delete_project($form_state['values']['om_pssp_project'])) ////// + { + drupal_set_message(t('Dis-Approved and Deleted Entire power system simulation project.'), 'status'); + $email_subject = t('[!site_name][power system simulation Project] Your uploaded power system simulation project have been marked as dis-approved', array( + '!site_name' => variable_get('site_name', '') + )); + $email_body = array( + 0 => t(' +Dear !user_name, + +We regret to inform you that your simulation and abstract for Power Systems Simulation Project at FOSSEE with the following details have been disapproved: + +Full Name: ' . $user_info->name_title . ' ' . $user_info->contributor_name . ' +Email : ' . $user_data->mail . ' +University/Institute : ' . $user_info->university . ' +City : ' . $user_info->city . ' + +Project Title : ' . $user_info->project_title . ' +Description of the simulation: ' . $user_info->description .' + +Reason for dis-approval: ' . $form_state['values']['message'] . ' + +Kindly note that the incorrect files will be deleted from all our databases. + +Thank you for participating in the Power Systems Simulation Project. You are welcome to submit a new proposal. + +Best Wishes, + +!site_name Power Systems Team, +FOSSEE,IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + )) + ); + $email_to = $user_data->mail; + $from = variable_get('om_pssp_from_email', ''); + $bcc = variable_get('om_pssp_emails', ''); + $cc = variable_get('om_pssp_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('om_pssp', 'standard', $email_to, language_default(), $params, $from, TRUE)) + { + drupal_set_message('Error sending email message.', 'error'); + } + } //om_pssp_abstract_delete_project($form_state['values']['om_pssp_project']) + else + { + drupal_set_message(t('Error Dis-Approving and Deleting Entire power system simulation project.'), 'error'); + } + // email + + } //$form_state['values']['om_pssp_actions'] == 3 + } //user_access('om_pssp project bulk manage code') + return $msg; + } //$form_state['clicked_button']['#value'] == 'Submit' +} +function _step_list_of_projects() +{ + $project_titles_list = array( + '0' => 'Please select...' + ); + /*$book_titles_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status = 1 OR approval_status = 3 ORDER BY book ASC");*/ + $query = db_select('arduino_projects_blog_proposal'); + $query->fields('arduino_projects_blog_proposal'); + $query->condition('submitted_steps', 1); + $query->condition('approval_status', 1); + $query->orderBy('project_title', 'ASC'); + $project_title_q = $query->execute(); + while ($project_title_data = $project_title_q->fetchObject()) { + $project_titles_list[$project_title_data->id] = $project_title_data->project_title; + } + return $project_titles_list; +} +function _ajax_bulk_get_step_list($proposal_id = 0) +{ + $steps_list = array( + '0' => 'Please select...' + ); + /*$book_chapters_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d ORDER BY number ASC", $preference_id);*/ + $query = db_select('arduino_projects_blog_step'); + $query->fields('arduino_projects_blog_step'); + $query->condition('proposal_id', $proposal_id); + $query->condition('approval_status', 0); + $query->orderBy('number', 'ASC'); + $steps_q = $query->execute(); + while ($steps_data = $steps_q->fetchObject()) { + $steps_list[$steps_data->number] = $steps_data->number . '. ' . $steps_data->name; + } + return $steps_list; +} +/*function _ajax_bulk_get_examples($chapter_id = 0) +{ + $book_examples = array( + '0' => 'Please select...' + ); + /*$book_examples_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d ORDER BY + CAST(SUBSTRING_INDEX(number, '.', 1) AS BINARY) ASC, + CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(number , '.', 2), '.', -1) AS UNSIGNED) ASC, + CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(number , '.', -1), '.', 1) AS UNSIGNED) ASC", $chapter_id); + $query = db_select('textbook_companion_example'); + $query->fields('textbook_companion_example'); + $query->condition('chapter_id', $chapter_id); + //$query->orderBy('CAST', 'ASC'); + //$query->orderBy('CAST', 'ASC'); + //$query->orderBy('CAST', 'ASC'); + $book_examples_q = $query->execute(); + while ($book_examples_data = $book_examples_q->fetchObject()) { + $book_examples[$book_examples_data->id] = $book_examples_data->number . ' (' . $book_examples_data->caption . ')'; + } + return $book_examples; +}*/ +function _bulk_list_book_actions() +{ + $book_actions = array( + '0' => 'Please select...' + ); + $book_actions[1] = 'Approve Entire Book'; + $book_actions[2] = 'Pending Review Entire Book'; + $book_actions[3] = 'Dis-Approve Entire Book (This will delete all the examples in the book)'; + $book_actions[4] = 'Delete Entire Book Including Proposal'; + return $book_actions; +} +function _bulk_list_step_actions() +{ + $chapter_actions = array( + '0' => 'Please select...' + ); + $chapter_actions[1] = 'Approve Step'; + $chapter_actions[2] = 'Resubmit the step'; + //$chapter_actions[3] = 'Dis-Approve Step (This will delete all the examples in the chapter)'; + return $chapter_actions; +} +function _bulk_list_example_actions() +{ + $example_actions = array( + '0' => 'Please select...' + ); + $example_actions[1] = 'Approve Approve Example'; + $example_actions[2] = 'Pending Review Example'; + $example_actions[3] = 'Dis-approve Example (This will delete the example)'; + return $example_actions; +} +/****************************** Ajax Callback function ***************************/ +function ajax_bulk_step_list_callback($form, $form_state) +{ + $commands = array(); + $project_default_value = $form_state['values']['project_title']; + if ($project_default_value > 0) { + /*$commands[] = ajax_command_html('#ajax_selected_book_notes', l('Notes for Reviewers', 'code_approval/notes/' . $project_default_value));*/ + $form['book_actions']['#options'] = _bulk_list_book_actions(); + $commands[] = ajax_command_replace('#ajax_selected_book_action', drupal_render($form['book_actions'])); + $form['step']['#options'] = _ajax_bulk_get_step_list($project_default_value); + $commands[] = ajax_command_replace('#ajax_select_step_list', drupal_render($form['step'])); + $commands[] = ajax_command_html('#ajax_download_chapter', ''); + $form['chapter_actions']['#options'] = _bulk_list_book_actions(); + $commands[] = ajax_command_replace('#ajax_selected_chapter_action', drupal_render($form['chapter_actions'])); + $commands[] = ajax_command_html('#ajax_selected_chapter_action', ''); + $commands[] = ajax_command_html('#ajax_selected_example', ''); + $form['example_actions']['#options'] = _bulk_list_example_actions(); + $commands[] = ajax_command_replace('#ajax_selected_example_action', drupal_render($form['example_actions'])); + $commands[] = ajax_command_html('#ajax_selected_example_action', ''); + $commands[] = ajax_command_html('#ajax_download_selected_example', ''); + $commands[] = ajax_command_html('#ajax_edit_selected_example', ''); + $form['example_files']['#title'] = ''; + $form['example_files']['#markup'] = ''; + $commands[] = ajax_command_replace('#ajax_example_files_list', drupal_render($form['example_files'])); + } else { + $commands[] = ajax_command_html('#ajax_selected_book', ''); + $commands[] = ajax_command_html('#ajax_selected_book_pdf', ''); + $commands[] = ajax_command_html('#ajax_selected_book_regenerate_pdf', ''); + $commands[] = ajax_command_html('#ajax_selected_book_notes', ''); + $form['step']['#options'] = _ajax_bulk_get_step_list(); + $commands[] = ajax_command_replace('#ajax_select_step_list', drupal_render($form['step'])); + $commands[] = ajax_command_html('#ajax_select_step_list', ''); + $form['book_actions']['#options'] = _bulk_list_book_actions(); + $commands[] = ajax_command_replace('#ajax_selected_book_action', drupal_render($form['book_actions'])); + $commands[] = ajax_command_html('#ajax_selected_book_action', ''); + $form['step_actions']['#options'] = _bulk_list_step_actions(); + $commands[] = ajax_command_replace('#ajax_selected_step_action', drupal_render($form['step_actions'])); + $commands[] = ajax_command_html('#ajax_selected_chapter_action', ''); + $commands[] = ajax_command_html('#ajax_download_chapter', ''); + $commands[] = ajax_command_html('#ajax_selected_example', ''); + $form['example_actions']['#options'] = _bulk_list_example_actions(); + $commands[] = ajax_command_replace('#ajax_selected_example_action', drupal_render($form['example_actions'])); + $commands[] = ajax_command_html('#ajax_selected_example_action', ''); + $commands[] = ajax_command_html('#ajax_download_selected_example', ''); + $commands[] = ajax_command_html('#ajax_edit_selected_example', ''); + $form['example_files']['#title'] = ''; + $form['example_files']['#markup'] = ''; + $commands[] = ajax_command_replace('#ajax_example_files_list', drupal_render($form['example_files'])); + } + return array( + '#type' => 'ajax', + '#commands' => $commands + ); +} +function ajax_bulk_step_details_list_callback($form, $form_state) +{ + $commands = array(); + $step_default_value = $form_state['values']['step']; + if ($step_default_value != 0) + { + $commands[] = ajax_command_html('#ajax_selected_step', _step_details($step_default_value)); + $form['om_pssp_actions']['#options'] = _bulk_list_step_actions(); + $commands[] = ajax_command_replace('#ajax_selected_step_action', drupal_render($form['step_actions'])); + } //$step_default_value != 0 + else + { + $commands[] = ajax_command_html('#ajax_selected_step', ''); + $commands[] = ajax_command_data('#ajax_selected_step', 'form_state_value_select', $form_state['values']['step']); + } + return array( + '#type' => 'ajax', + '#commands' => $commands + ); +} +function ajax_bulk_example_files_callback($form, $form_state) +{ + $commands = array(); + $example_list_default_value = $form_state['values']['example']; + //var_dump($example_list_default_value); + if ($example_list_default_value > 0) { + /*************************************************************************************/ + /*$example_list_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $form_state['values']['example']);*/ + $query = db_select('textbook_companion_example_files'); + $query->fields('textbook_companion_example_files'); + $query->condition('example_id', $example_list_default_value); + $example_list_q = $query->execute(); + if ($example_list_q) { + $example_files_rows = array(); + while ($example_list_data = $example_list_q->fetchObject()) { + $example_file_type = ''; + switch ($example_list_data->filetype) { + case 'S': + $example_file_type = 'Source or Main file'; + break; + case 'R': + $example_file_type = 'Result file'; + break; + case 'X': + $example_file_type = 'xcos file'; + break; + default: + $example_file_type = 'Unknown'; + break; + } + $example_files_rows[] = array( + l($example_list_data->filename, 'textbook-companion/download/file/' . $example_list_data->id), + $example_file_type + ); + } + /* dependency files */ + /*$dependency_list_q = db_query("SELECT dependency.id as dependency_id, dependency.filename as dependency_filename, dependency.caption as dependency_caption + FROM {textbook_companion_example_dependency} example_dependency LEFT JOIN {textbook_companion_dependency_files} dependency + ON example_dependency.dependency_id = dependency.id + WHERE example_dependency.example_id = %d", $form_state['values']['example']);*/ + /* + $query = db_select('textbook_companion_example_dependency', 'example_dependency'); + $query->fields('dependency', array('id', 'filename', 'caption')); + $query->addField('dependency','id','dependency_id'); + $query->addField('dependency','filename','dependency_filename'); + $query->addField('dependency','caption','dependency_caption'); + $query->leftJoin('textbook_companion_dependency_files', 'dependency', 'example_dependency.dependency_id = dependency.id'); + $query->condition('example_dependency.example_id', $form_state['values']['example']); + $dependency_list_q = $query->execute(); + + while ($dependency_list_data = $dependency_list_q->fetchObject()) + { + $example_file_type = 'Dependency file'; + $temp_caption = ''; + if ($dependency_list_data->dependency_caption) + $temp_caption = ' (' . $dependency_list_data->dependency_caption . ')'; + $example_files_rows[] = array(l($dependency_list_data->dependency_filename, 'download/dependency/' . $dependency_list_data->dependency_id) . $temp_caption, $example_file_type); + } + */ + /* creating list of files table */ + $example_files_header = array( + 'Filename', + 'Type' + ); + $example_files = theme('table', array( + 'header' => $example_files_header, + 'rows' => $example_files_rows + )); + $form['example_files']['#title'] = 'List of example files'; + $form['example_files']['#markup'] = $example_files; + $commands[] = ajax_command_replace('#ajax_example_files_list', drupal_render($form['example_files'])); + $commands[] = ajax_command_html('#ajax_download_selected_example', l('Download Example', 'textbook-companion/download/example/' . $example_list_default_value)); + $commands[] = ajax_command_html('#ajax_edit_selected_example', l('Edit Example', 'textbook-companion/code-approval/editcode/' . $example_list_default_value)); + $form['example_actions']['#options'] = _bulk_list_example_actions(); + $commands[] = ajax_command_replace('#ajax_selected_example_action', drupal_render($form['example_actions'])); + //$commands[] = ajax_command_html('#ajax_selected_example_action', '' ); + } + } else { + $commands[] = ajax_command_html('#ajax_download_selected_example', ''); + $commands[] = ajax_command_html('#ajax_edit_selected_example', ''); + $form['example_files']['#title'] = ''; + $form['example_files']['#markup'] = ''; + $commands[] = ajax_command_replace('#ajax_example_files_list', drupal_render($form['example_files'])); + $form['example_actions']['#options'] = _bulk_list_example_actions(); + $commands[] = ajax_command_replace('#ajax_selected_example_action', drupal_render($form['example_actions'])); + $commands[] = ajax_command_html('#ajax_selected_example_action', ''); + } + return array( + '#type' => 'ajax', + '#commands' => $commands + ); +} +function ajax_bulk_chapter_actions_callback() +{ + //if($form_state['values']['chapter_actions'] > 0){ + // $form['book_actions']['#options'] = _bulk_list_book_actions(); + //$commands[] = ajax_command_replace('#ajax_selected_book_action',drupal_render($form['book_actions'])); + // } + return array( + '#type' => 'ajax', + '#commands' => $commands + ); +} + +function _step_details($step_id) +{ + $return_html = ""; + $query = db_select('arduino_projects_blog_step'); + $query->fields('arduino_projects_blog_step'); + $query->condition('number', $step_id); + $step_data = $query->execute()->fetchObject(); + //var_dump($step_data);die; + $query = db_select('arduino_projects_blog_proposal'); + $query->fields('arduino_projects_blog_proposal'); + $query->condition('id', $step_data->proposal_id); + $proposal_data = $query->execute()->fetchObject(); + $query = db_select('arduino_projects_blog_step_information'); + $query->fields('arduino_projects_blog_step_information'); + $query->condition('step_id', $step_data->id); + $step_info_data = $query->execute()->fetchObject(); + //var_dump($abstracts_pro);die; + $query = db_select('arduino_projects_blog_step_files'); + $query->fields('arduino_projects_blog_step_files'); + $query->condition('step_id', $step_data->id); + $query->condition('filetype', 'I'); + $step_images = $query->execute()->fetchObject(); + $images_count = $query->execute()->rowCount(); + $query = db_select('arduino_projects_blog_step_files'); + $query->fields('arduino_projects_blog_step_files'); + $query->condition('step_id', $step_data->id); + $query->condition('filetype', 'G'); + $step_gifs = $query->execute()->fetchObject(); + $gifs_count = $query->execute()->rowCount(); + if(!$step_info_data->video){ + $video = 'Not uploaded'; + } + else{ + $video = convertLinkToEmbed($step_info_data->video, 450, 350); + } + if($images_count > 0){ + $download_step_images = l('Download Images','arduino-projects/download/step-images/' . $step_id); + } + else{ + $download_step_images = 'Not uploaded'; + } + if($gifs_count > 0){ + $download_step_gifs = l('Download Gifs','arduino-projects/download/step-gifs/' . $step_id); + } + else{ + $download_step_gifs = 'Not uploaded'; + } + $return_html .= '<strong>Contributor Name:</strong><br />' . $proposal_data->contributor_name . '<br /><br />'; + $return_html .= '<strong>Title of the Project:</strong><br />' . $proposal_data->project_title . '<br /><br />'; + $return_html .= '<strong>Step name:</strong><br />' . $step_data->name . '<br /><br />'; + $return_html .= '<strong>Step description:</strong><br />' . $step_info_data->description; + $return_html .= '<strong>Video</strong><br />' . $video . '<br /><br />'; + /*$return_html .= '<strong>Uploaded an abstract (brief outline) of the project:</strong><br />' . $abstract_filename . '<br /><br />'; + $return_html .= '<strong>Upload the power system simulation for the developed process:</strong><br />' . $abstracts_query_process_filename . '<br /><br />';*/ + $return_html .= '<strong>Images uploaded for this step</strong><br />' . $download_step_images . '<br /><br />'; + $return_html .= '<strong>Gifs uploaded for this step</strong><br />' . $download_step_gifs; + return $return_html; +} + +function bulk_approval_form($form, &$form_state) +{ + $options_first = _bulk_list_of_project_titles(); + $selected = isset($form_state['values']['project_title']) ? $form_state['values']['project_title'] : key($options_first); + $form = array(); + $form['project_title'] = array( + '#type' => 'select', + '#title' => t('Title of the power system simulation project'), + '#options' => _bulk_list_of_project_titles(), + '#default_value' => $selected, + '#ajax' => array( + + 'callback' => 'ajax_bulk_om_pssp_abstract_details_callback' + ), + '#suffix' => '<div id="ajax_selected_om_pssp"></div><div id="ajax_selected_om_pssp_pdf"></div>' + ); + $form['project_actions'] = array( + '#type' => 'select', + '#title' => t('Please select action for the project'), + '#options' => _bulk_list_project_actions(), + '#default_value' => 0, + '#prefix' => '<div id="ajax_selected_om_pssp_action" style="color:red;">', + '#suffix' => '</div>', + '#states' => array( + 'invisible' => array( + ':input[name="om_pssp_project"]' => array( + 'value' => 0 + ) + ) + ) + ); + $form['message'] = array( + '#type' => 'textarea', + '#title' => t('Please specify the reason for marking resubmit/disapproval'), + '#prefix' => '<div id= "message_submit">', + '#states' => array( + 'visible' => array( + array( + ':input[name="project_actions"]' => array( + 'value' => 3 + ) + ), + 'or', + array( + ':input[name="project_actions"]' => array( + 'value' => 2 + ) + ) + ), + 'required' => array( + array( + array( + ':input[name="project_actions"]' => array( + 'value' => 2 + ) + ), + 'or', + array( + ':input[name="project_actions"]' => array( + 'value' => 3 + ) + ), + ) + ) + ), + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit'), + '#states' => array( + 'invisible' => array( + ':input[name="lab"]' => array( + 'value' => 0 + ) + ) + ) + ); + return $form; +} +function ajax_bulk_om_pssp_abstract_details_callback($form, $form_state) +{ + $commands = array(); + $om_pssp_project_default_value = $form_state['values']['om_pssp_project']; + if ($om_pssp_project_default_value != 0) + { + //$commands[] = ajax_command_html('#ajax_selected_om_pssp', _om_pssp_details($om_pssp_project_default_value)); + $form['om_pssp_actions']['#options'] = _bulk_list_project_actions(); + $commands[] = ajax_command_replace('#ajax_selected_om_pssp_action', drupal_render($form['om_pssp_actions'])); + } //$om_pssp_project_default_value != 0 + else + { + $commands[] = ajax_command_html('#ajax_selected_om_pssp', ''); + $commands[] = ajax_command_data('#ajax_selected_om_pssp', 'form_state_value_select', $form_state['values']['om_pssp_project']); + } + return array( + '#type' => 'ajax', + '#commands' => $commands + ); +} +/************************************************************/ +function om_pssp_abstract_bulk_approval_form_submit($form, &$form_state) +{ + global $user; + $msg = ''; + $root_path = om_pssp_path(); + if ($form_state['clicked_button']['#value'] == 'Submit') + { + if ($form_state['values']['om_pssp_project']) + // om_pssp_abstract_del_lab_pdf($form_state['values']['om_pssp_project']); + if (user_access('om pssp bulk manage abstract')) + { + $query = db_select('om_pssp_proposal'); + $query->fields('om_pssp_proposal'); + $query->condition('id', $form_state['values']['om_pssp_project']); + $user_query = $query->execute(); + $user_info = $user_query->fetchObject(); + $user_data = user_load($user_info->uid); + if ($form_state['values']['om_pssp_actions'] == 1) + { + // approving entire project // + $query = db_select('om_pssp_submitted_abstracts'); + $query->fields('om_pssp_submitted_abstracts'); + $query->condition('proposal_id', $form_state['values']['om_pssp_project']); + $abstracts_q = $query->execute(); + $experiment_list = ''; + while ($abstract_data = $abstracts_q->fetchObject()) + { + db_query("UPDATE {om_pssp_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 {om_pssp_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_goto('powersystems/pssp/manage-proposal/all'); + drupal_set_message(t('Approved power system simulation project.'), 'status'); + // email + $email_subject = t('[!site_name][power system simulation Project] Your uploaded power system simulation project have been approved', array( + '!site_name' => variable_get('site_name', '') + )); + $email_body = array( + 0 => t(' + +Dear !user_name, + +Congratulations! +Your simulation and abstract for Power Systems Simulation Project at FOSSEE with the following details have been approved. + +Full Name: ' . $user_info->name_title . ' ' . $user_info->contributor_name . ' +Email : ' . $user_data->mail . ' +University/Institute : ' . $user_info->university . ' +City : ' . $user_info->city . ' + +Project Title : ' . $user_info->project_title . ' +Description of the simulation: ' . $user_info->description .' + +Kindly send us the internship forms as early as possible for processing your honorarium on time. In case you have already sent these forms, please share the the consignment number or tracking id with us. + +Note: It will take upto 30 days from the time we receive your forms, to process your honorarium. + + +Best Wishes, + +!site_name Power Systems 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('om_pssp_from_email', ''); + $bcc = variable_get('om_pssp_emails', ''); + $cc = variable_get('om_pssp_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('om_pssp', 'standard', $email_to, language_default(), $params, $from, TRUE)) + { + $msg = drupal_set_message('Error sending email message.', 'error'); + } //!drupal_mail('om_pssp', 'standard', $email_to, language_default(), $params, $from, TRUE) + } //$form_state['values']['om_pssp_actions'] == 1 + elseif ($form_state['values']['om_pssp_actions'] == 2) + { + if (strlen(trim($form_state['values']['message'])) <= 30) + { + form_set_error('message', t('')); + $msg = drupal_set_message("Please mention the reason for marking resubmit. Minimum 30 character required", 'error'); + return $msg; + } + //pending review entire project + $query = db_select('om_pssp_submitted_abstracts'); + $query->fields('om_pssp_submitted_abstracts'); + $query->condition('proposal_id', $form_state['values']['om_pssp_project']); + $abstracts_q = $query->execute(); + $experiment_list = ''; + while ($abstract_data = $abstracts_q->fetchObject()) + { + db_query("UPDATE {om_pssp_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 {om_pssp_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 {om_pssp_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][power system simulation Project] Your uploaded power system simulation 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 . '. +Description of the simulation: ' . $user_info->description . ' + +Reason: ' . $form_state['values']['message'] . ' + +Looking forward for the re-submission from you with the above suggested changes. + +Best Wishes, + +!site_name Power Systems 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('om_pssp_from_email', ''); + $bcc = variable_get('om_pssp_emails', ''); + $cc = variable_get('om_pssp_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('om_pssp', 'standard', $email_to, language_default(), $params, $from, TRUE)) + { + drupal_set_message('Error sending email message.', 'error'); + } //!drupal_mail('om_pssp', 'standard', $email_to, language_default(), $params, $from, TRUE) + } //$form_state['values']['om_pssp_actions'] == 2 + elseif ($form_state['values']['om_pssp_actions'] == 3) //disapprove and delete entire power system simulation 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('om pssp bulk delete code')) + { + $msg = drupal_set_message(t('You do not have permission to Bulk Dis-Approved and Deleted Entire Lab.'), 'error'); + return $msg; + } //!user_access('om_pssp bulk delete code') + if (om_pssp_abstract_delete_project($form_state['values']['om_pssp_project'])) ////// + { + drupal_set_message(t('Dis-Approved and Deleted Entire power system simulation project.'), 'status'); + $email_subject = t('[!site_name][power system simulation Project] Your uploaded power system simulation project have been marked as dis-approved', array( + '!site_name' => variable_get('site_name', '') + )); + $email_body = array( + 0 => t(' +Dear !user_name, + +We regret to inform you that your simulation and abstract for Power Systems Simulation Project at FOSSEE with the following details have been disapproved: + +Full Name: ' . $user_info->name_title . ' ' . $user_info->contributor_name . ' +Email : ' . $user_data->mail . ' +University/Institute : ' . $user_info->university . ' +City : ' . $user_info->city . ' + +Project Title : ' . $user_info->project_title . ' +Description of the simulation: ' . $user_info->description .' + +Reason for dis-approval: ' . $form_state['values']['message'] . ' + +Kindly note that the incorrect files will be deleted from all our databases. + +Thank you for participating in the Power Systems Simulation Project. You are welcome to submit a new proposal. + +Best Wishes, + +!site_name Power Systems Team, +FOSSEE,IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + )) + ); + $email_to = $user_data->mail; + $from = variable_get('om_pssp_from_email', ''); + $bcc = variable_get('om_pssp_emails', ''); + $cc = variable_get('om_pssp_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('om_pssp', 'standard', $email_to, language_default(), $params, $from, TRUE)) + { + drupal_set_message('Error sending email message.', 'error'); + } + } //om_pssp_abstract_delete_project($form_state['values']['om_pssp_project']) + else + { + drupal_set_message(t('Error Dis-Approving and Deleting Entire power system simulation project.'), 'error'); + } + // email + + } //$form_state['values']['om_pssp_actions'] == 3 + } //user_access('om_pssp project bulk manage code') + return $msg; + } //$form_state['clicked_button']['#value'] == 'Submit' +} +/**********************************************************/ +function _bulk_list_of_project_titles() +{ + + $project_titles = array( + '0' => 'Please select...' + ); + $query = db_select('arduino_projects_blog_proposal'); + $query->fields('arduino_projects_blog_proposal'); + $query->condition('submitted_steps', 1); + $query->condition('approval_status', 1); + $query->orderBy('project_title', 'ASC'); + $project_titles_q = $query->execute(); + while ($project_titles_data = $project_titles_q->fetchObject()) + { + $query_step = db_select('arduino_projects_blog_step'); + $query_step->fields('arduino_projects_blog_step'); + $query_step->condition('proposal_id', $project_titles_data->id); + $query_step->condition('approval_status', 1); + $query_step_count = $query_step->execute()->rowCount(); + if($query_step_count == $project_titles_data->no_of_steps_approved){ + $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_project_actions() +{ + $om_pssp_actions = array( + 0 => 'Please select...' + ); + $om_pssp_actions[1] = 'Approve Entire Project'; + $om_pssp_actions[2] = 'Resubmit All Project files'; + $om_pssp_actions[3] = 'Dis-Approve Entire Project (This will delete the Project)'; + //$om_pssp_actions[4] = 'Delete Entire power system simulation Project Including Proposal'; + return $om_pssp_actions; +} +function _om_pssp_details($om_pssp_proposal_id) +{ + $return_html = ""; + $query_pro = db_select('om_pssp_proposal'); + $query_pro->fields('om_pssp_proposal'); + $query_pro->condition('id', $om_pssp_proposal_id); + $abstracts_pro = $query_pro->execute()->fetchObject(); + //var_dump($abstracts_pro);die; + $query_pdf = db_select('om_pssp_submitted_abstracts_file'); + $query_pdf->fields('om_pssp_submitted_abstracts_file'); + $query_pdf->condition('proposal_id', $om_pssp_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('om_pssp_submitted_abstracts_file'); + $query_process->fields('om_pssp_submitted_abstracts_file'); + $query_process->condition('proposal_id', $om_pssp_proposal_id); + $query_process->condition('filetype', 'S'); + $abstracts_query_process = $query_process->execute()->fetchObject(); + $query = db_select('om_pssp_submitted_abstracts'); + $query->fields('om_pssp_submitted_abstracts'); + $query->condition('proposal_id', $om_pssp_proposal_id); + $abstracts_q = $query->execute()->fetchObject(); + if($abstracts_q->other_libraries_used == 1) + { + $other_libraries_used = "Yes"; + } + else + { + $other_libraries_used = "No"; + } + 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', 'powersystems/pssp/abstract-code/upload'); + $abstracts_query_process_filename = "File not uploaded"; + } + $download_om_pssp = l('Download power system simulation project','powersystems/pssp/full-download/project/'.$om_pssp_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 power system simulation Project:</strong><br />' . $abstracts_pro->project_title . '<br /><br />'; + $return_html .= '<strong>Other libraries used:</strong><br />' . $other_libraries_used . '<br /><br />'; + $return_html .= '<strong>Uploaded an abstract (brief outline) of the project:</strong><br />' . $abstract_filename . '<br /><br />'; + $return_html .= '<strong>Upload the power system simulation for the developed process:</strong><br />' . $abstracts_query_process_filename . '<br /><br />'; + $return_html .= $download_om_pssp; + return $return_html; +}
\ No newline at end of file diff --git a/download.inc b/download.inc index 9f9aea9..9699074 100755 --- a/download.inc +++ b/download.inc @@ -61,42 +61,149 @@ function arduino_projects_blog_download_reference_images() } } //$zip_file_count > 0 else { - drupal_set_message("There are no power system simulation project in this proposal to download", 'error'); - drupal_goto('powersystems'); + drupal_set_message("There are no reference images in this proposal to download", 'error'); + drupal_goto('arduino-projects/manage-proposal'); } } -/* -function arduino_projects_blog_download_reference_images() { - $proposal_id = arg(3); + +function arduino_projects_blog_download_step_images() +{ + global $user; + $id = arg(3); $root_path = arduino_projects_blog_files_path(); - $query = db_select('arduino_projects_blog_proposal_images'); - $query->fields('arduino_projects_blog_proposal_images'); - $query->condition('proposal_id', $proposal_id); - $result = $query->execute(); - while($arduino_projects_blog_project_files = $result->fetchObject()){ - //var_dump($arduino_projects_blog_project_files);die; - $query1 = db_select('arduino_projects_blog_proposal'); - $query1->fields('arduino_projects_blog_proposal'); - $query1->condition('id', $proposal_id); - $result1 = $query1->execute(); - $arduino_projects_blog = $result1->fetchObject(); - $directory_name = $arduino_projects_blog->directory_name . '/project_files/'; - $samplecodename = $arduino_projects_blog_project_files->path; - 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/zip"); - header('Content-disposition: attachment; filename="' . $samplecodename . '"'); - header("Content-Length: " . filesize($root_path . $samplecodename)); - header("Content-Transfer-Encoding: binary"); - header("Expires: 0"); - header("Pragma: no-cache"); - readfile($root_path . $samplecodename); - ob_end_flush(); - ob_clean(); -} + //var_dump($root_path);die; + $query = db_select('arduino_projects_blog_step'); + $query->fields('arduino_projects_blog_step'); + $query->condition('number', $id); + $step_data = $query->execute()->fetchObject(); + //var_dump($step_data);die; + $query = db_select('arduino_projects_blog_proposal'); + $query->fields('arduino_projects_blog_proposal'); + $query->condition('id', $step_data->proposal_id); + $proposal_data = $query->execute()->fetchObject(); + $step_images_directory_path = $proposal_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('om_pssp_proposal'); + $query->fields('om_pssp_proposal'); + $query->condition('id', $id); + $om_pssp_udc_q = $query->execute(); + $query = db_select('om_pssp_proposal'); + $query->fields('om_pssp_proposal'); + $query->condition('id', $id);*/ + $query = db_select('arduino_projects_blog_step_files'); + $query->fields('arduino_projects_blog_step_files'); + $query->condition('step_id', $step_data->id); + $query->condition('filetype', 'I'); + $reference_images = $query->execute(); + while ($reference_images_files = $reference_images->fetchObject()) { + $zip->addFile($root_path . $reference_images_files->filepath, $step_images_directory_path . str_replace(' ', '_', basename($reference_images_files->filename))); + } + $zip_file_count = $zip->numFiles; + //var_dump($zip_file_count);die; + $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(' ', '_', $proposal_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(' ', '_', $proposal_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 images in this step to download", 'error'); + drupal_goto('arduino-projects/code-approval/bulk'); + } } -*/
\ No newline at end of file + +function arduino_projects_blog_download_step_gifs() +{ + global $user; + $id = arg(3); + $root_path = arduino_projects_blog_files_path(); + //var_dump($root_path);die; + $query = db_select('arduino_projects_blog_step'); + $query->fields('arduino_projects_blog_step'); + $query->condition('number', $id); + $step_data = $query->execute()->fetchObject(); + //var_dump($step_data);die; + $query = db_select('arduino_projects_blog_proposal'); + $query->fields('arduino_projects_blog_proposal'); + $query->condition('id', $step_data->proposal_id); + $proposal_data = $query->execute()->fetchObject(); + $step_images_directory_path = $proposal_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('om_pssp_proposal'); + $query->fields('om_pssp_proposal'); + $query->condition('id', $id); + $om_pssp_udc_q = $query->execute(); + $query = db_select('om_pssp_proposal'); + $query->fields('om_pssp_proposal'); + $query->condition('id', $id);*/ + $query = db_select('arduino_projects_blog_step_files'); + $query->fields('arduino_projects_blog_step_files'); + $query->condition('step_id', $step_data->id); + $query->condition('filetype', 'G'); + $reference_images = $query->execute(); + while ($reference_images_files = $reference_images->fetchObject()) { + $zip->addFile($root_path . $reference_images_files->filepath, $step_images_directory_path . str_replace(' ', '_', basename($reference_images_files->filename))); + } + $zip_file_count = $zip->numFiles; + //var_dump($zip_file_count);die; + $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(' ', '_', $proposal_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(' ', '_', $proposal_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 gifs in this step to download", 'error'); + drupal_goto('arduino-projects/code-approval/bulk'); + } +}
\ No newline at end of file diff --git a/editstep.inc b/editstep.inc new file mode 100755 index 0000000..a4af74d --- /dev/null +++ b/editstep.inc @@ -0,0 +1,1043 @@ +<?php +// $Id$ +/******************************************************************************/ +/***************************** EDIT EXAMPLE ***********************************/ +/******************************************************************************/ +function upload_step_edit_form($form, &$form_state, $no_js_use = FALSE) + { + global $user; + $step_id = arg(4); + /* get example details */ + /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $example_id); + $example_data = db_fetch_object($example_q);*/ + $query = db_select('arduino_projects_blog_step'); + $query->fields('arduino_projects_blog_step'); + $query->condition('id',$step_id); + $step_q = $query->execute(); + $step_data = $step_q->fetchObject(); + //var_dump($step_data);die; + $query = db_select('arduino_projects_blog_step_information'); + $query->fields('arduino_projects_blog_step_information'); + $query->condition('step_id', $step_id); + $query->range(0, 1); + $step_info_q = $query->execute(); + $step_info_data = $step_info_q->fetchObject(); + if (!$step_info_data) + { + drupal_set_message(t("Invalid step selected."), 'error'); + drupal_goto(''); + return; + } + if ($step_info_data->approval_status != 0) + { + drupal_set_message(t("You cannot edit an example after it has been approved or dis-approved. Please contact site administrator if you want to edit this example."), 'error'); + drupal_goto(''); + return; + } + //var_dump($step_info_data);die; + /* get examples files */ + $images = ""; + $images_id = 0; + $gifs = ""; + $gifs_id = 0; + /*$step_files_q = db_query("SELECT * FROM {arduino_projects_blog_step_files} WHERE example_id = %d", $example_id);*/ + $query = db_select('arduino_projects_blog_step_files'); + $query->fields('arduino_projects_blog_step_files'); + $query->condition('step_id', $step_id); + $step_files_q = $query->execute(); + while ($step_files_data = $step_files_q->fetchObject()) + { + if ($step_files_data->filetype == "I") + { + $images = l($step_files_data->filename, 'arduino-projects/download/file/' . $step_files_data->id); + $images_id = $step_files_data->id; + //var_dump($source_file);die; + } + else if ($step_files_data->filetype == "G") + { + $gifs = l($step_files_data->filename, 'arduino-projects/download/file/' . $step_files_data->id); + $gifs_id = $step_files_data->id; + //var_dump($source_file);die; + } + } + /* get chapter details */ + /*$chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $example_data->chapter_id); + $chapter_data = db_fetch_object($chapter_q);*/ + // $query = db_select('textbook_companion_chapter'); + // $query->fields('textbook_companion_chapter'); + // $query->condition('id', $example_data->chapter_id); + // $result = $query->execute(); + // $chapter_data = $result->fetchObject(); + // if (!$chapter_data) + // { + // drupal_set_message(t("Invalid chapter selected."), 'error'); + // drupal_goto(''); + // return; + // } + /* get preference details */ + /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $chapter_data->preference_id); + $preference_data = db_fetch_object($preference_q);*/ + /*$query = db_select('textbook_companion_preference'); + $query->fields('textbook_companion_preference'); + $query->condition('id', $chapter_data->preference_id); + $result = $query->execute(); + $preference_data = $result->fetchObject(); + if (!$preference_data) + { + drupal_set_message(t("Invalid book selected."), 'error'); + drupal_goto(''); + return; + } + if ($preference_data->approval_status != 1) + { + drupal_set_message(t("Cannot edit example. Either the book proposal has not been approved or it has been rejected."), 'error'); + drupal_goto(''); + return; + }*/ + /* get proposal details */ + /*$proposal_q = db_query("SELECT * FROM {arduino_projects_blog_proposal} WHERE id = %d", $preference_data->proposal_id); + $proposal_data = db_fetch_object($proposal_q);*/ + $query = db_select('arduino_projects_blog_proposal'); + $query->fields('arduino_projects_blog_proposal'); + $query->condition('id', $step_data->proposal_id); + $result = $query->execute(); + $proposal_data = $result->fetchObject(); + if (!$proposal_data) + { + drupal_set_message(t("Invalid proposal selected."), 'error'); + drupal_goto(''); + return; + } + if ($proposal_data->uid != $user->uid) + { + drupal_set_message(t("You do not have permissions to edit this example."), 'error'); + drupal_goto(''); + return; + } + $user_data = user_load($proposal_data->uid); + $form['#redirect'] = 'textbook-companion/code'; + $form['#attributes'] = array( + 'enctype' => "multipart/form-data" + ); + $form['project_title'] = array( + '#type' => 'item', + '#markup' => $proposal_data->project_title, + '#title' => t('Project title') + ); + $form['contributor_name'] = array( + '#type' => 'item', + '#markup' => $proposal_data->contributor_name, + '#title' => t('Contributor Name') + ); + $form['number'] = array( + '#type' => 'item', + '#title' => t('Step No'), + '#markup' => $step_data->number + ); + if($step_data->number <= 5){ + $form['name'] = array( + '#type' => 'item', + '#title' => t('Title of the Step'), + '#markup' => $step_data->name + ); + } + else{ + $form['name'] = array( + '#type' => 'textfield', + '#title' => t('Title of the Step'), + '#default_value' => $step_data->name + ); + } + $form['step_description'] = array( + '#type' => 'text_format', + '#title' => t('Description'), + '#required' => TRUE, + '#default_value' => $step_info_data->description, + '#format' => $step_info_data->description_type + ); + $form['video'] = array( + '#type' => 'textarea', + '#title' => t('Video'), + '#default_value' => $step_info_data->video + ); + //$dest_path = $proposal_data->directory_name . '/' + if ($images) + { + $form['uplpoaded_images'] = array( + '#markup' => '<h5><p> Edit existing step images</p></h5>(Select Check box to delete existing photos)', + '#prefix' => '<div id="uploaded_images"><table><tr>', + '#suffix' => '' + ); + $query = db_select('arduino_projects_blog_step_files'); + $query->fields('arduino_projects_blog_step_files'); + $query->condition('step_id', $step_id); + $query->condition('filetype', 'I'); + $step_files_q = $query->execute(); + /*$query1 = db_select('arduino_projects_blog_proposal_images'); + $query1->fields('arduino_projects_blog_proposal_images'); + $query1->condition('proposal_id', $proposal_id); + $result1 = $query1->execute();*/ + while ($row1 = $step_files_q->fetchObject()) { + $form['imagecheck@' . $row1->id] = array( + '#type' => 'checkbox', + '#field_suffix' => '<img style="width:500px; padding-left :20px;" src=' . $GLOBALS['base_url'] . "/project_uploads/" . $row1->filepath . ' />' + ); + } + $form['enduploadphotos'] = array( + '#markup' => '', + '#prefix' => '', + '#suffix' => '</tr></table></div>' + ); + $form['step_images'] = array( + '#type' => 'fieldset', + '#tree' => TRUE, + '#prefix' => '<div id="names-fieldset-wrapper">', + '#suffix' => '</div>', + '#title' => t('Upload images related to the step'), + ); + if (empty($form_state['image_names'])) { + $form_state['image_names'] = 1; + } + for ($i = 0; $i < $form_state['image_names']; $i++) { + $temp_no = $i; + $form['step_images'][$i]['image'] = array( + //'#title' => t('Add Event Image'), + '#type' => 'file', + '#weight' => '5', + '#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('step_image_extensions', '') . t('</span>'), + // We need this to know which file element this is. + // By default drupal would name all as files[step_images] + '#name' => 'files[step_images_' . $i . '_name]', + //'#attributes' => array('multiple' => 'multiple'), + //'#upload_location' => 'public://', + '#upload_validators' => array( + // Pass the maximum file size in bytes + 'file_validate_size' => array(2*1024), + ), + ); + $form['step_images']["images_count"] = array( + "#type" => "hidden", + "#value" => $temp_no + ); + } + if($i < 5){ + $form['step_images']['add_image'] = array( + '#type' => 'submit', + '#value' => t('Add Image'), + '#limit_validation_errors' => array(), + '#submit' => array( + 'step_images_add_more_add_one' + ), + '#ajax' => array( + 'callback' => 'step_images_add_more_callback', + 'wrapper' => 'names-fieldset-wrapper' + ) + ); + } + if ($form_state['image_names'] > 1) { + $form['step_images']['remove_image'] = array( + '#type' => 'submit', + '#value' => t('Remove Image'), + '#limit_validation_errors' => array(), + '#submit' => array( + 'step_images_add_more_remove_one' + ), + '#ajax' => array( + 'callback' => 'step_images_add_more_callback', + 'wrapper' => 'names-fieldset-wrapper' + ) + ); + } + if ($no_js_use) { + if (!empty($form['step_images']['remove_image']['#ajax'])) { + unset($form['step_images']['remove_image']['#ajax']); + } + unset($form['step_images']['add_image']['#ajax']); + } + + } + else + { + $form['step_images'] = array( + '#type' => 'fieldset', + '#tree' => TRUE, + '#prefix' => '<div id="names-fieldset-wrapper">', + '#suffix' => '</div>', + '#title' => t('Upload images related to the step'), + ); + if (empty($form_state['image_names'])) { + $form_state['image_names'] = 1; + } + for ($i = 0; $i < $form_state['image_names']; $i++) { + $temp_no = $i; + $form['step_images'][$i]['image'] = array( + //'#title' => t('Add Event Image'), + '#type' => 'file', + '#weight' => '5', + '#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('step_image_extensions', '') . t('</span>'), + // We need this to know which file element this is. + // By default drupal would name all as files[step_images] + '#name' => 'files[step_images_' . $i . '_name]', + //'#attributes' => array('multiple' => 'multiple'), + //'#upload_location' => 'public://', + '#upload_validators' => array( + // Pass the maximum file size in bytes + 'file_validate_size' => array(2*1024), + ), + ); + $form['step_images']["images_count"] = array( + "#type" => "hidden", + "#value" => $temp_no + ); + } + if($i < 5){ + $form['step_images']['add_image'] = array( + '#type' => 'submit', + '#value' => t('Add Image'), + '#limit_validation_errors' => array(), + '#submit' => array( + 'step_images_add_more_add_one' + ), + '#ajax' => array( + 'callback' => 'step_images_add_more_callback', + 'wrapper' => 'names-fieldset-wrapper' + ) + ); + } + if ($form_state['image_names'] > 1) { + $form['step_images']['remove_image'] = array( + '#type' => 'submit', + '#value' => t('Remove Image'), + '#limit_validation_errors' => array(), + '#submit' => array( + 'step_images_add_more_remove_one' + ), + '#ajax' => array( + 'callback' => 'step_images_add_more_callback', + 'wrapper' => 'names-fieldset-wrapper' + ) + ); + } + if ($no_js_use) { + if (!empty($form['step_images']['remove_image']['#ajax'])) { + unset($form['step_images']['remove_image']['#ajax']); + } + unset($form['step_images']['add_image']['#ajax']); + } + } + if ($gifs) + { + $form['uplpoaded_gifs'] = array( + '#markup' => '<h5><p> Edit existing step gifs</p></h5>(Select Check box to delete existing photos)', + '#prefix' => '<div id="uploaded_gifs"><table><tr>', + '#suffix' => '' + ); + $query = db_select('arduino_projects_blog_step_files'); + $query->fields('arduino_projects_blog_step_files'); + $query->condition('step_id', $step_id); + $query->condition('filetype', 'G'); + $step_files_q = $query->execute(); + /*$query1 = db_select('arduino_projects_blog_proposal_gifs'); + $query1->fields('arduino_projects_blog_proposal_gifs'); + $query1->condition('proposal_id', $proposal_id); + $result1 = $query1->execute();*/ + while ($row1 = $step_files_q->fetchObject()) { + $form['gifcheck@' . $row1->id] = array( + '#type' => 'checkbox', + '#field_suffix' => '<img style="width:500px; padding-left :20px;" src=' . $GLOBALS['base_url'] . "/project_uploads/" . $row1->filepath . ' />' + ); + } + $form['enduploadphotos'] = array( + '#markup' => '', + '#prefix' => '', + '#suffix' => '</tr></table></div>' + ); + $form['step_gifs'] = array( + '#type' => 'fieldset', + '#tree' => TRUE, + '#prefix' => '<div id="gifs-fieldset-wrapper">', + '#suffix' => '</div>', + '#title' => t('Upload gifs related to the step'), + ); + if (empty($form_state['gif_names'])) { + $form_state['gif_names'] = 1; + } + for ($p = 0; $p < $form_state['gif_names']; $p++) { + $temp_no = $p; + $form['step_gifs'][$p]['gifs'] = array( + //'#title' => t('Add Event Image'), + '#type' => 'file', + '#weight' => '5', + '#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: gif</span>'), + // We need this to know which file element this is. + // By default drupal would name all as files[step_gifs] + '#name' => 'files[step_gifs_' . $p . '_name]', + //'#attributes' => array('multiple' => 'multiple'), + //'#upload_location' => 'public://', + '#upload_validators' => array( + 'file_validate_extensions' => ['gif'], + // Pass the maximum file size in bytes + 'file_validate_size' => array(2*1024), + ), + ); + $form['step_gifs']["images_count"] = array( + "#type" => "hidden", + "#value" => $temp_no + ); + } + if($p < 5){ + $form['step_gifs']['add_gif'] = array( + '#type' => 'submit', + '#value' => t('Add Gif'), + '#limit_validation_errors' => array(), + '#submit' => array( + 'step_gifs_add_more_add_one' + ), + '#ajax' => array( + 'callback' => 'step_gifs_add_more_callback', + 'wrapper' => 'gifs-fieldset-wrapper' + ) + ); + } + if ($form_state['gif_names'] > 1) { + $form['step_gifs']['remove_gif'] = array( + '#type' => 'submit', + '#value' => t('Remove Gif'), + '#limit_validation_errors' => array(), + '#submit' => array( + 'step_gifs_add_more_remove_one' + ), + '#ajax' => array( + 'callback' => 'step_gifs_add_more_callback', + 'wrapper' => 'gifs-fieldset-wrapper' + ) + ); + } + if ($no_js_use) { + if (!empty($form['step_gifs']['remove_gif']['#ajax'])) { + unset($form['step_gifs']['remove_gif']['#ajax']); + } + unset($form['step_gifs']['add_gif']['#ajax']); + } + + } + else + { + $form['step_gifs'] = array( + '#type' => 'fieldset', + '#tree' => TRUE, + '#prefix' => '<div id="gifs-fieldset-wrapper">', + '#suffix' => '</div>', + '#title' => t('Upload gifs related to the step'), + ); + if (empty($form_state['gif_names'])) { + $form_state['gif_names'] = 1; + } + for ($p = 0; $p < $form_state['gif_names']; $p++) { + $temp_no = $p; + $form['step_gifs'][$p]['gifs'] = array( + //'#title' => t('Add Event Image'), + '#type' => 'file', + '#weight' => '5', + '#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: gif</span>'), + // We need this to know which file element this is. + // By default drupal would name all as files[step_gifs] + '#name' => 'files[step_gifs_' . $p . '_name]', + //'#attributes' => array('multiple' => 'multiple'), + //'#upload_location' => 'public://', + '#upload_validators' => array( + 'file_validate_extensions' => ['gif'], + // Pass the maximum file size in bytes + 'file_validate_size' => array(2*1024), + ), + ); + $form['step_gifs']["images_count"] = array( + "#type" => "hidden", + "#value" => $temp_no + ); + } + if($p < 5){ + $form['step_gifs']['add_gif'] = array( + '#type' => 'submit', + '#value' => t('Add Gif'), + '#limit_validation_errors' => array(), + '#submit' => array( + 'step_gifs_add_more_add_one' + ), + '#ajax' => array( + 'callback' => 'step_gifs_add_more_callback', + 'wrapper' => 'gifs-fieldset-wrapper' + ) + ); + } + if ($form_state['gif_names'] > 1) { + $form['step_gifs']['remove_gif'] = array( + '#type' => 'submit', + '#value' => t('Remove Gif'), + '#limit_validation_errors' => array(), + '#submit' => array( + 'step_gifs_add_more_remove_one' + ), + '#ajax' => array( + 'callback' => 'step_gifs_add_more_callback', + 'wrapper' => 'gifs-fieldset-wrapper' + ) + ); + } + if ($no_js_use) { + if (!empty($form['step_gifs']['remove_gif']['#ajax'])) { + unset($form['step_gifs']['remove_gif']['#ajax']); + } + unset($form['step_gifs']['add_gif']['#ajax']); + } + } + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); + $form['cancel'] = array( + '#type' => 'item', + '#markup' => l(t('Cancel'), 'textbook-companion/code') + ); + return $form; + } +function step_images_add_more_callback($form, $form_state) { + return $form['step_images']; +} + + +function step_images_add_more_add_one($form, &$form_state) { + $form_state['image_names']++; + $form_state['rebuild'] = TRUE; + //$form_state['no_redirect'] = TRUE; +} + + +function step_images_add_more_remove_one($form, &$form_state) { + if ($form_state['image_names'] > 1) { + $form_state['image_names']--; + } + $form_state['rebuild'] = TRUE; +} +function step_gifs_add_more_callback($form, $form_state) { + return $form['step_gifs']; +} + + +function step_gifs_add_more_add_one($form, &$form_state) { + $form_state['gif_names']++; + $form_state['rebuild'] = TRUE; + //$form_state['no_redirect'] = TRUE; +} + + +function step_gifs_add_more_remove_one($form, &$form_state) { + if ($form_state['gif_names'] > 1) { + $form_state['gif_names']--; + } + $form_state['rebuild'] = TRUE; +} +function upload_step_edit_form_validate($form, &$form_state) + { + /*if (isset($_FILES['files'])) + { + /* check for valid filename extensions + foreach ($_FILES['files']['name'] as $file_form_name => $file_name) + { + if ($file_name) + { + if (strstr($file_form_name, 'image')) + $file_type = 'I'; + else if (strstr($file_form_name, 'gifs')) + $file_type = 'G'; + $allowed_extensions_str = ''; + switch ($file_type) + { + case 'I': + $allowed_extensions_str = variable_get('step_image_extensions', ''); + break; + case 'G': + $allowed_extensions_str = 'gif'; + break; + } + //$allowed_extensions_str = variable_get('arduino_projects_blog_source_extensions', ''); + $allowed_extensions = explode(',', $allowed_extensions_str); + $temp_ext = explode('.', strtolower($_FILES['files']['name'][$file_form_name])); + $temp_extension = end($temp_ext); + $temp_extension = substr($_FILES['files']['name'][$file_form_name], strripos($_FILES['files']['name'][$file_form_name], '.')); // get file name + //var_dump($temp_extension); die; + 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 (!arduino_projects_blog_check_valid_filename($_FILES['files']['name'][$file_form_name])) + form_set_error($file_form_name, t('Invalid file name specified. Only alphabets, numbers and underscore is allowed as a valid filename.')); + } + } + }*/ + } +function upload_step_edit_form_submit($form, &$form_state) + { + global $user; + $step_id = arg(4); + /* get example details */ + /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $example_id); + $example_data = db_fetch_object($example_q);*/ + $query = db_select('arduino_projects_blog_step'); + $query->fields('arduino_projects_blog_step'); + $query->condition('id',$step_id); + $step_q = $query->execute(); + $step_data = $step_q->fetchObject(); + //var_dump($step_data);die; + $query = db_select('arduino_projects_blog_step_information'); + $query->fields('arduino_projects_blog_step_information'); + $query->condition('step_id', $step_id); + $query->range(0, 1); + $step_info_q = $query->execute(); + $step_info_data = $step_info_q->fetchObject(); + if (!$step_info_data) + { + drupal_set_message(t("Invalid step selected."), 'error'); + drupal_goto(''); + return; + } + if ($step_info_data->approval_status != 0) + { + drupal_set_message(t("You cannot edit an example after it has been approved or dis-approved. Please contact site administrator if you want to edit this example."), 'error'); + drupal_goto(''); + return; + } + $query = db_select('arduino_projects_blog_proposal'); + $query->fields('arduino_projects_blog_proposal'); + $query->condition('id', $step_data->proposal_id); + $result = $query->execute(); + $proposal_data = $result->fetchObject(); + if (!$proposal_data) + { + drupal_set_message(t("Invalid proposal selected."), 'error'); + drupal_goto(''); + return; + } + if ($proposal_data->uid != $user->uid) + { + drupal_set_message(t("You do not have permissions to edit this example."), 'error'); + drupal_goto(''); + return; + } + /* creating directories */ + $root_path = arduino_projects_blog_files_path(); + $dest_path = $proposal_data->directory_name . '/'; + if (!is_dir($root_path . $dest_path)) + mkdir($root_path . $dest_path); + $dest_path .= 'project_files/'; + if (!is_dir($root_path . $dest_path)) + mkdir($root_path . $dest_path); + $dest_path .= 'Step' . $step_data->number . '/'; + if (!is_dir($root_path . $dest_path)) + mkdir($root_path . $dest_path); + $filepath = $proposal_data->directory_name . '/project_files/Step' . $step_data->number . '/'; + /* updating example caption */ + /*db_query("UPDATE {textbook_companion_example} SET caption = '%s' WHERE id = %d", $form_state['values']['example_caption'], $example_id);*/ + if($step_data->number > 5){ + $query = db_update('arduino_projects_blog_step'); + $query->fields(array( + 'name' => $form_state['values']['name'] + )); + $query->condition('id', $step_id); + $num_updated = $query->execute(); + } + $query = db_update('arduino_projects_blog_step_information'); + $query->fields(array( + 'description' => $form_state['values']['step_description']['value'], + 'description_type' => $form_state['values']['step_description']['format'], + 'video' => $form_state['values']['video'], + 'timestamp' => time() + )); + $query->condition('step_id', $step_id); + $step_info_updated = $query->execute(); + $deletecounter_images = 0; + $query_img = db_select('arduino_projects_blog_step_files'); + $query_img->fields('arduino_projects_blog_step_files'); + $query_img->condition('step_id', $step_id); + $query_img->condition('filetype', 'I'); + $result_img = $query_img->execute(); + //$root_path= arduino_projects_blog_files_path(); + while ($row_img = $result_img->fetchObject()) { + if ($form_state['values']['imagecheck@' . $row_img->id] == 1) { + if (file_exists($root_path . $row_img->filepath)) { + unlink($root_path .$row_img->filepath); + $query2 = db_delete('arduino_projects_blog_step_files'); + $query2->condition('id', $row_img->id); + $delete_img = $query2->execute(); + if ($delete_img != 0) { + $deletecounter_images++; + } + } + else { + drupal_set_message(t('Error Could not delete :') . $filename . t(', file does not exist'), 'error'); + } + } + } + $deletecounter_gifs = 0; + $query_img = db_select('arduino_projects_blog_step_files'); + $query_img->fields('arduino_projects_blog_step_files'); + $query_img->condition('step_id', $step_id); + $query_img->condition('filetype', 'G'); + $result_img = $query_img->execute(); + //$root_path= arduino_projects_blog_files_path(); + while ($row_img = $result_img->fetchObject()) { + if ($form_state['values']['gifcheck@' . $row_img->id] == 1) { + if (file_exists($root_path . $row_img->filepath)) { + unlink($root_path .$row_img->filepath); + $query2 = db_delete('arduino_projects_blog_step_files'); + $query2->condition('id', $row_img->id); + $delete_img = $query2->execute(); + if ($delete_img != 0) { + $deletecounter_gifs++; + } + } + else { + drupal_set_message(t('Error Could not delete :') . $filename . t(', file does not exist'), 'error'); + } + } + } + foreach ($_FILES['files']['name'] as $file_form_name => $file_name) + { + if ($file_name) + { + /* checking file type */ + if (strstr($file_form_name, 'images')) + { + $file_type = 'I'; + } //strstr($file_form_name, 'upload_flowsheet_developed_process') + else if (strstr($file_form_name, 'gifs')) + { + $file_type = 'G'; + } + + //$file_type = 'S'; + switch ($file_type) { + case 'I': + $dest_path = $filepath . 'images/'; + //var_dump($root_path . $dest_path);die; + if (!is_dir($root_path . $dest_path)) + mkdir($root_path . $dest_path); + 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'); + return; + } + /* uploading file */ + else if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name])) + { + $query = "INSERT INTO {arduino_projects_blog_step_files} (step_id, filename, filepath,filemime, filesize, filetype, timestamp) + VALUES (:step_id, :filename ,:filepath,:filemime, :filesize, :filetype, :timestamp)"; + $args = array( + ":step_id" => $step_id, + ":filename" => $_FILES['files']['name'][$file_form_name], + ":filepath" => $dest_path . $_FILES['files']['name'][$file_form_name], + ":filemime" => mime_content_type($root_path . $dest_path . $_FILES['files']['name'][$file_form_name]), + ":filesize" => $_FILES['files']['size'][$file_form_name], + ":filetype" => $file_type, + ":timestamp" => time() + ); + $result = db_query($query, $args, array( + 'return' => Database::RETURN_INSERT_ID + )); + drupal_set_message($file_name . ' uploaded successfully.', 'status'); + } + else + { + drupal_set_message('Error uploading file : ' . $dest_path . $file_name, 'error'); + } + break; + case 'G': + $dest_path = $filepath . 'gifs/'; + //var_dump($root_path . $dest_path);die; + if (!is_dir($root_path . $dest_path)) + mkdir($root_path . $dest_path); + //var_dump($root_path . $dest_path);die; + 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'); + return; + } + /* uploading file */ + else if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name])) + { + $query = "INSERT INTO {arduino_projects_blog_step_files} (step_id, filename, filepath,filemime, filesize, filetype, timestamp) + VALUES (:step_id, :filename ,:filepath,:filemime, :filesize, :filetype, :timestamp)"; + $args = array( + ":step_id" => $step_id, + ":filename" => $_FILES['files']['name'][$file_form_name], + ":filepath" => $dest_path . $_FILES['files']['name'][$file_form_name], + ":filemime" => mime_content_type($root_path . $dest_path . $_FILES['files']['name'][$file_form_name]), + ":filesize" => $_FILES['files']['size'][$file_form_name], + ":filetype" => $file_type, + ":timestamp" => time() + ); + $result = db_query($query, $args, array( + 'return' => Database::RETURN_INSERT_ID + )); + drupal_set_message($file_name . ' uploaded successfully.', 'status'); + } + else + { + drupal_set_message('Error uploading file : ' . $dest_path . '/' . $file_name, 'error'); + } + break; + } + } + } + drupal_set_message('Step uploaded successfully.', 'status'); + /* sending email */ + $email_to = $user->mail; + $from = variable_get('textbook_companion_from_email', ''); + $bcc = variable_get('textbook_companion_emails', ''); + $cc = variable_get('textbook_companion_cc_emails', ''); + $param['example_updated']['step_id'] = $step_id; + $param['example_updated']['user_id'] = $user->uid; + $param['example_updated']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + /*if (!drupal_mail('textbook_companion', 'example_updated', $email_to, language_default(), $param, $from, TRUE)) + drupal_set_message('Error sending email message.', 'error'); + drupal_set_message(t("Step successfully udpated."), 'status');*/ + drupal_goto('arduino-projects/code'); + } +/******************************************************************************/ +/**************************** EDIT CHAPTER TITLE ******************************/ +/******************************************************************************/ +function edit_chapter_title_form($form, $form_state) + { + global $user; + /************************ start approve book details ************************/ + /*$proposal_q = db_query("SELECT * FROM {arduino_projects_blog_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid); + $proposal_data = db_fetch_object($proposal_q);*/ + $query = db_select('arduino_projects_blog_proposal'); + $query->fields('arduino_projects_blog_proposal'); + $query->condition('uid', $user->uid); + $query->orderBy('id', 'DESC'); + $query->range(0, 1); + $result = $query->execute(); + $proposal_data = $result->fetchObject(); + if (!$proposal_data) + { + drupal_set_message("Please submit a " . l('proposal', 'textbook-companion/proposal') . ".", 'error'); + drupal_goto('textbook-companion/code'); + } + if ($proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4) + { + switch ($proposal_data->proposal_status) + { + case 0: + drupal_set_message(t('We have already received your proposal. We will get back to you soon.'), 'status'); + drupal_goto('textbook-companion/code'); + return; + break; + case 2: + drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'proposal') . '.'), 'error'); + drupal_goto('textbook-companion/code'); + return; + break; + case 3: + drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'textbook-companion/proposal') . '.'), 'status'); + drupal_goto('textbook-companion/code'); + return; + break; + default: + drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error'); + drupal_goto('textbook-companion/code'); + return; + break; + } + } + /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id); + $preference_data = db_fetch_object($preference_q);*/ + $query = db_select('textbook_companion_preference'); + $query->fields('textbook_companion_preference'); + $query->condition('proposal_id', $proposal_data->id); + $query->condition('approval_status', 1); + $query->range(0, 1); + $result = $query->execute(); + $preference_data = $result->fetchObject(); + if (!$preference_data) + { + drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error'); + drupal_goto('textbook-companion/code'); + return; + } + /************************ end approve book details **************************/ + $chapter_id = arg(4); + /*$chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d AND preference_id = %d", $chapter_id, $preference_data->id); + $chapter_data = db_fetch_object($chapter_q);*/ + $query = db_select('textbook_companion_chapter'); + $query->fields('textbook_companion_chapter'); + $query->condition('id', $chapter_id); + $query->condition('preference_id', $preference_data->id); + $result = $query->execute(); + $chapter_data = $result->fetchObject(); + if (!$chapter_data) + { + drupal_set_message(t('Invalid chapter.'), 'error'); + drupal_goto('textbook-companion/code'); + return; + } + $form['#redirect'] = 'textbook-companion/code'; + $form['book_details']['book'] = array( + '#type' => 'item', + '#markup' => $preference_data->book, + '#title' => t('Title of the Book') + ); + $form['contributor_name'] = array( + '#type' => 'item', + '#markup' => $proposal_data->full_name, + '#title' => t('Contributor Name') + ); + $form['number'] = array( + '#type' => 'item', + '#title' => t('Chapter No'), + '#markup' => $chapter_data->number + ); + $form['chapter_title'] = array( + '#type' => 'textfield', + '#title' => t('Title of the Chapter'), + '#size' => 40, + '#maxlength' => 255, + '#required' => TRUE, + '#default_value' => $chapter_data->name + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); + $form['cancel'] = array( + '#type' => 'markup', + '#value' => l(t('Cancel'), 'textbook_companion/code') + ); + return $form; + } +function edit_chapter_title_form_validate($form, &$form_state) + { + if (!check_name($form_state['values']['chapter_title'])) + form_set_error('chapter_title', t('Title of the Chapter can contain only alphabets, numbers and spaces.')); + } +function edit_chapter_title_form_submit($form, &$form_state) + { + global $user; + /************************ start approve book details ************************/ + /*$proposal_q = db_query("SELECT * FROM {arduino_projects_blog_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid); + $proposal_data = db_fetch_object($proposal_q);*/ + $query = db_select('arduino_projects_blog_proposal'); + $query->fields('arduino_projects_blog_proposal'); + $query->condition('uid', $user->uid); + $query->orderBy('id', 'DESC'); + $query->range(0, 1); + $result = $query->execute(); + $proposal_data = $result->fetchObject(); + if (!$proposal_data) + { + drupal_set_message("Please submit a " . l('proposal', 'textbook-companion/proposal') . ".", 'error'); + drupal_goto('textbook-companion/code'); + } + if ($proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4) + { + switch ($proposal_data->proposal_status) + { + case 0: + drupal_set_message(t('We have already received your proposal. We will get back to you soon.'), 'status'); + drupal_goto('textbook-companion/code'); + return; + break; + case 2: + drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'proposal') . '.'), 'error'); + drupal_goto('textbook-companion/code'); + return; + break; + case 3: + drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'textbook-companion/proposal') . '.'), 'status'); + drupal_goto('textbook-companion/code'); + return; + break; + default: + drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error'); + drupal_goto('textbook-companion/code'); + return; + break; + } + } + /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id); + $preference_data = db_fetch_object($preference_q);*/ + $query = db_select('textbook_companion_preference'); + $query->fields('textbook_companion_preference'); + $query->condition('proposal_id', $proposal_data->id); + $query->condition('approval_status', 1); + $query->range(0, 1); + $result = $query->execute(); + $preference_data = $result->fetchObject(); + if (!$preference_data) + { + drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error'); + drupal_goto('textbook-companion/code'); + return; + } + /************************ end approve book details **************************/ + $chapter_id = arg(4); + /*$chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d AND preference_id = %d", $chapter_id, $preference_data->id); + $chapter_data = db_fetch_object($chapter_q);*/ + $query = db_select('textbook_companion_chapter'); + $query->fields('textbook_companion_chapter'); + $query->condition('id', $chapter_id); + $query->condition('preference_id', $preference_data->id); + $result = $query->execute(); + $chapter_data = $result->fetchObject(); + if (!$chapter_data) + { + drupal_set_message(t('Invalid chapter.'), 'error'); + drupal_goto('textbookcompanion/code'); + return; + } + /*db_query("UPDATE {textbook_companion_chapter} SET name = '%s' WHERE id = %d", $form_state['values']['chapter_title'], $chapter_id);*/ + $query = db_update('textbook_companion_chapter'); + $query->fields(array( + 'name' => $form_state['values']['chapter_title'] + )); + $query->condition('id', $chapter_id); + $num_updated = $query->execute(); + drupal_set_message(t('Title of the Chapter updated.'), 'status'); + } +/******************************************************************************/ +/************************** GENERAL FUNCTIONS *********************************/ +/******************************************************************************/ +function _list_of_book_titles() + { + $book_titles = array( + '0' => 'Please select...' + ); + /*$book_titles_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status = 1 OR approval_status = 3 ORDER BY book ASC");*/ + $query = db_select('textbook_companion_preference'); + $query->fields('textbook_companion_preference'); + $or = db_or(); + $or->condition('approval_status', 1); + $or->condition('approval_status', 3); + $query->condition($or); + $query->orderBy('book', 'ASC'); + $book_titles_q = $query->execute(); + while ($book_titles_data = $book_titles_q->fetchObject()) + { + $book_titles[$book_titles_data->id] = $book_titles_data->book . ' (Written by ' . $book_titles_data->author . ')'; + } + return $book_titles; + } @@ -16,7 +16,6 @@ function arduino_projects_blog_mail($key, &$message, $params) $query->condition('id', $params['arduino_projects_blog_proposal_received']['proposal_id']); $query->range(0, 1); $proposal_data = $query->execute()->fetchObject(); - $phpdate = time( $proposal_data->creation_date ); $user_data = user_load($params['arduino_projects_blog_proposal_received']['user_id']); $message['headers'] = $params['arduino_projects_blog_proposal_received']['headers']; $message['subject'] = t('[!site_name][Arduino Project] Your Arduino Project proposal has been received', array( @@ -39,10 +38,8 @@ Project Title: ' . $proposal_data->project_title . ' Abstract: ' . $proposal_data->abstract . ' References: ' . $proposal_data->reference . ' - Your proposal is under review. You will be notified via email about the approval/disapproval within ten working days. - Best Wishes, !site_name Team, @@ -61,7 +58,6 @@ FOSSEE, IIT Bombay', array( $query->condition('id', $params['arduino_projects_blog_proposal_resubmit']['proposal_id']); $query->range(0, 1); $proposal_data = $query->execute()->fetchObject(); - $phpdate = time( $proposal_data->creation_date ); $user_data = user_load($params['arduino_projects_blog_proposal_resubmit']['user_id']); $message['headers'] = $params['arduino_projects_blog_proposal_resubmit']['headers']; $message['subject'] = t('[!site_name][Arduino Project] Your Arduino Project proposal has been marked for resubmission', array( @@ -111,7 +107,6 @@ FOSSEE, IIT Bombay', array( $query->condition('id', $params['arduino_projects_blog_proposal_disapproved']['proposal_id']); $query->range(0, 1); $proposal_data = $query->execute()->fetchObject(); - $phpdate = time( $proposal_data->creation_date ); $user_data = user_load($params['arduino_projects_blog_proposal_disapproved']['user_id']); $message['headers'] = $params['arduino_projects_blog_proposal_disapproved']['headers']; $message['subject'] = t('[!site_name][Arduino Project] Your Arduino Project Project proposal has been disapproved', array( diff --git a/manage_proposal.inc b/manage_proposal.inc index f4c3508..5dbb985 100755 --- a/manage_proposal.inc +++ b/manage_proposal.inc @@ -707,19 +707,6 @@ function arduino_projects_blog_proposal_edit_form($form, &$form_state) return; } $user_data = user_load($proposal_data->uid); - $form['name_title'] = array( - '#type' => 'select', - '#title' => t('Title'), - '#options' => array( - 'Dr' => 'Dr', - 'Prof' => 'Prof', - 'Mr' => 'Mr', - 'Mrs' => 'Mrs', - 'Ms' => 'Ms' - ), - '#required' => TRUE, - '#default_value' => $proposal_data->name_title - ); $form['contributor_name'] = array( '#type' => 'textfield', '#title' => t('Name of the Proposer'), @@ -733,20 +720,6 @@ function arduino_projects_blog_proposal_edit_form($form, &$form_state) '#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 - ), - '#required' => FALSE - ); $form['university'] = array( '#type' => 'textfield', '#title' => t('University/Institute'), @@ -865,13 +838,13 @@ else{ '#required' => TRUE, '#default_value' => $proposal_data->project_title ); - $form['description'] = array( + $form['abstract'] = array( '#type' => 'textarea', '#title' => t('Description of the Project'), '#size' => 250, '#maxlength' => 250, '#required' => TRUE, - '#default_value' => $proposal_data->description + '#default_value' => $proposal_data->abstract ); $form['reference'] = array( '#type' => 'textarea', diff --git a/my_proposals.inc b/my_proposals.inc index 4c3ff5f..d79a55f 100644 --- a/my_proposals.inc +++ b/my_proposals.inc @@ -233,7 +233,7 @@ else{ $temp_no = $i; $form['reference_files'][$i]['image'] = array( //'#title' => t('Add Event Image'), - '#type' => 'file', + '#type' => 'managed_file', '#weight' => '5', '#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('reference_image_extensions', '') . '</span>', // We need this to know which file element this is. diff --git a/proposal.inc b/proposal.inc index e522722..69b883b 100755 --- a/proposal.inc +++ b/proposal.inc @@ -18,6 +18,7 @@ Solution Display : function arduino_projects_blog_proposal_form($form, &$form_state, $no_js_use = FALSE) { global $user; + $root_path = arduino_projects_blog_files_path(); /************************ start approve book details ************************/ if ($user->uid == 0) { @@ -215,13 +216,7 @@ function arduino_projects_blog_proposal_form($form, &$form_state, $no_js_use = F '#attributes' => array( 'placeholder' => 'The links to the documents or websites which are referenced while proposing this project.' ) - ); - /*$form['reference_files']['reference_image'] = array( - '#type' => 'file', - '#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('reference_image_extensions', '') . '</span>' - );*/ $form['reference_files'] = array( '#type' => 'fieldset', '#tree' => TRUE, @@ -241,7 +236,9 @@ function arduino_projects_blog_proposal_form($form, &$form_state, $no_js_use = F '#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('reference_image_extensions', '') . '</span>', // We need this to know which file element this is. // By default drupal would name all as files[reference_files] - '#name' => 'files[reference_files_' . $i . '_name]' + '#name' => 'files[reference_files_' . $i . '_name]', + //'#attributes' => array('multiple' => 'multiple'), + //'#upload_location' => 'public://images/proposal_images', ); $form['reference_files']["images_count"] = array( "#type" => "hidden", diff --git a/settings.inc b/settings.inc index d8f8457..64cca99 100755 --- a/settings.inc +++ b/settings.inc @@ -38,6 +38,21 @@ function arduino_projects_blog_settings_form($form, $form_state) '#required' => TRUE, '#default_value' => variable_get('reference_image_extensions', '') ); + $form['extensions']['step_image_extensions'] = array( + '#type' => 'textfield', + '#title' => t('Allowed file extensions for uploading step images'), + '#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('step_image_extensions', '') + ); + $form['no_of_images_allowed_project_submission'] = array( + '#type' => 'textfield', + '#title' => t('Enter the number of images that can be uploaded during project submission'), + '#size' => 50, + '#default_value' => variable_get('no_of_images_allowed_project_submission', '') + ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit') @@ -54,5 +69,7 @@ function arduino_projects_blog_settings_form_submit($form, &$form_state) variable_set('arduino_projects_blog_cc_emails', $form_state['values']['cc_emails']); variable_set('arduino_projects_blog_from_email', $form_state['values']['from_email']); variable_set('reference_image_extensions', $form_state['values']['reference_image']); + variable_set('step_image_extensions', $form_state['values']['step_image_extensions']); + variable_set('no_of_images_allowed_project_submission', $form_state['values']['no_of_images_allowed_project_submission']); drupal_set_message(t('Settings updated'), 'status'); } diff --git a/upload_project.inc b/upload_project.inc new file mode 100755 index 0000000..ca7f604 --- /dev/null +++ b/upload_project.inc @@ -0,0 +1,543 @@ +<?php +// $Id$ +function list_steps() + { + global $user; + /************************ start approve book details ************************/ + /*$proposal_q = db_query("SELECT * FROM {arduino_projects_blog_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid); + $proposal_data = db_fetch_object($proposal_q);*/ + $query = db_select('arduino_projects_blog_proposal'); + $query->fields('arduino_projects_blog_proposal'); + $query->condition('uid', $user->uid); + $query->orderBy('id', 'DESC'); + $query->range(0, 1); + $result = $query->execute(); + $proposal_data = $result->fetchObject(); + $intro_query = db_select('arduino_projects_blog_introduction_step'); + $intro_query->fields('arduino_projects_blog_introduction_step'); + $intro_query->condition('proposal_id', $proposal_data->id); + $intro_query_result = $intro_query->execute(); + $intro_query_data = $intro_query_result->fetchObject(); + if (!$proposal_data) + { + drupal_set_message("Please submit a " . l('proposal', 'arduino-projects/proposal') . ".", 'error'); + drupal_goto(''); + } + if ($proposal_data->approval_status != 1 && $proposal_data->approval_status != 4 && $proposal_data->approval_status != 2) + { + switch ($proposal_data->approval_status) + { + case 0: + drupal_set_message(t('We have already received your proposal. We will get back to you soon.'), 'status'); + drupal_goto(''); + return; + break; + case 2: + drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'arduino-projects/proposal') . '.'), 'error'); + drupal_goto(''); + return; + break; + case 3: + drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'arduino-projects/proposal') . '.'), 'status'); + drupal_goto(''); + return; + break; + default: + drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error'); + drupal_goto(''); + return; + break; + } + } + + + /*$preference_q = db_query("SELECT * FROM {arduino_projects_blog_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id); + $preference_data = db_fetch_object($preference_q);*/ + /*$query = db_select('arduino_projects_blog_preference'); + $query->fields('arduino_projects_blog_preference'); + $query->condition('proposal_id', $proposal_data->id); + $query->condition('approval_status', 1); + $query->range(0, 1); + $result = $query->execute(); + $preference_data = $result->fetchObject(); + if ($preference_data->submited_all_examples_code == 1) + { + drupal_set_message(t('You have submited your all codes for this book to review, hence you can not upload more code, for any query please write us.'), 'status'); + drupal_goto(''); + return; + } + if (!$preference_data) + { + drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error'); + drupal_goto(''); + return; + }*/ + if ($proposal_data->submitted_steps == 1) + { + drupal_set_message(t('You have submited your all steps for this project to review, hence you can not upload more steps, for any query please write us.'), 'status'); + drupal_goto(''); + return; + } + /************************ end approve book details **************************/ + $return_html = ''; + $return_html .= '<strong>Title of the Book:</strong><br />' . $proposal_data->project_title . '<br /><br />'; + $return_html .= '<strong>Contributor Name:</strong><br />' . $proposal_data->contributor_name . '<br /><br />'; + if($intro_query_data->is_submitted == 1){ + $return_html .= '<strong>Introduction</strong><br />'; + $return_html .= '<strong>Description:</strong>' . $intro_query_data->description; + $return_html .= '<strong>Demo Video:</strong><br />' . convertLinkToEmbed($intro_query_data->demo_video, 450, 350) . '<br />'; + } + else{ + $return_html .= l('Update Introduction', 'arduino-projects/code/update-introduction') . '<br />'; + } + $return_html .= l('Upload Steps', 'arduino-projects/code/upload') . '<br />'; + /* get step list */ + $step_rows = array(); + /*$step_q = db_query("SELECT * FROM {arduino_projects_blog_step} WHERE preference_id = %d ORDER BY number ASC", $preference_data->id);*/ + $query = db_select('arduino_projects_blog_step'); + $query->fields('arduino_projects_blog_step'); + $query->condition('proposal_id', $proposal_data->id); + $query->orderBy('number', 'ASC'); + $step_q = $query->execute(); + while ($step_data = $step_q->fetchObject()) + { + /* get example list */ + /* $example_q = db_query("SELECT count(*) as example_count FROM {arduino_projects_blog_step_information} WHERE step_id = %d", $step_data->id); + $example_data = db_fetch_object($example_q);*/ + $query = db_select('arduino_projects_blog_step_information'); + $query->fields('arduino_projects_blog_step_information'); + //$query->addExpression('count(*)', 'example_count'); + $query->condition('step_id', $step_data->id); + $result = $query->execute(); + $example_data = $result->fetchObject(); + $step_rows[] = array( + $step_data->number, + $step_data->name, + //$step_data->name . ' (' . l('Edit', 'arduino-projects/code/step/edit/' . $step_data->id) . ')', + //$example_data->example_count, + l('Edit', 'arduino-projects/code/step/edit/' . $step_data->id) . ' | ' .l('View', 'arduino-projects/code/view-step/' . $step_data->id) + ); + } + /* check if there are any steps */ + if (!$step_rows) + { + drupal_set_message(t('No uploads found.'), 'status'); + return $return_html; + } + $step_header = array( + 'Step No.', + 'Title of the Step', + //'Uploaded Examples', + 'Actions' + ); + $return_html .= theme('table', array( + 'header' => $step_header, + 'rows' => $step_rows + )); + $step_count = $step_q->rowCount(); + if($step_count >= 5){ + $submited_all_steps = drupal_get_form("all_steps_submitted_check_form",$proposal_data->id); + $return_html .= drupal_render($submited_all_steps); + } + return $return_html; + } + +function update_introduction() + { + return drupal_get_form('update_introduction_form'); + } +function update_introduction_form($form, &$form_state) + { + global $user; + /************************ start approve book details ************************/ + /*$proposal_q = db_query("SELECT * FROM {arduino_projects_blog_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid); + $proposal_data = db_fetch_object($proposal_q);*/ + $query = db_select('arduino_projects_blog_proposal'); + $query->fields('arduino_projects_blog_proposal'); + $query->condition('uid', $user->uid); + $query->orderBy('id', 'DESC'); + $query->range(0, 1); + $result = $query->execute(); + $proposal_data = $result->fetchObject(); + if (!$proposal_data) + { + drupal_set_message("Please submit a " . l('proposal', 'textbook-companion/proposal') . ".", 'error'); + drupal_goto(''); + } + if ($proposal_data->approval_status != 1 && $proposal_data->approval_status != 4) + { + switch ($proposal_data->approval_status) + { + case 0: + drupal_set_message(t('We have already received your proposal. We will get back to you soon.'), 'status'); + drupal_goto(''); + return; + break; + case 2: + drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'textbook-companion/proposal') . '.'), 'error'); + drupal_goto(''); + return; + break; + case 3: + drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'textbook-companion/proposal') . '.'), 'status'); + drupal_goto(''); + return; + break; + case 5: + drupal_set_message(t('You have submitted your all codes.'), 'status'); + drupal_goto(''); + return; + break; + default: + drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error'); + drupal_goto(''); + return; + break; + } + } + /*$preference_q = db_query("SELECT * FROM {arduino_projects_blog_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id); + $proposal_data = db_fetch_object($preference_q);*/ + /*$query = db_select('arduino_projects_blog_preference'); + $query->fields('arduino_projects_blog_preference'); + $query->condition('proposal_id', $proposal_data->id); + $query->condition('approval_status', 1); + $query->range(0, 1); + $result = $query->execute(); + $proposal_data = $result->fetchObject(); + if (!$proposal_data) + { + drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error'); + drupal_goto(''); + return; + }*/ + $form['#attributes'] = array( + 'enctype' => "multipart/form-data" + ); + $form['proposal_id'] =array( + '#type' => 'hidden', + '#default_value' => $proposal_data->id + ); + $form['title'] = array( + '#type' => 'item', + '#markup' => t('Introduction'), + '#title' => t('Title'), + '#default_value' => t('Introduction') + ); + $form['description'] = array( + '#type' => 'text_format', + '#title' => t('Description'), + '#required' => TRUE, + '#format' => 'contributor_format' + ); + $form['demo_video'] = array( + '#type' => 'textarea', + '#title' => t('Demo video'), + '#size' => 600, + '#maxlength' => 600, + '#required' => TRUE, + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); + $form['cancel'] = array( + '#type' => 'item', + '#markup' => l('Cancel', 'arduino-projects/code') + ); + return $form; + } + + function update_introduction_form_submit($form, &$form_state) + { + global $user; + 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"]; + $result = "INSERT INTO {arduino_projects_blog_introduction_step} + ( + uid, + proposal_id, + title, + description, + description_type, + demo_video, + creation_date, + is_submitted + ) VALUES + ( + :uid, + :proposal_id, + :title, + :description, + :description_type, + :demo_video, + :creation_date, + :is_submitted + )"; + $args = array( + ":uid" => $user->uid, + ":proposal_id" => $v['proposal_id'], + ":title" => "Introduction", + ":description" => $v['description']['value'], + ":description_type" => $v['description']['format'], + ":demo_video" => $v['demo_video'], + ":creation_date" => time(), + ":is_submitted" => 1 + ); + $intro_id = db_query($result, $args, array( + 'return' => Database::RETURN_INSERT_ID + )); + drupal_set_message(t('Introduction update successfully.'), 'status'); + drupal_goto('arduino-projects/code'); + } + + + + function view_steps() + { + global $user; + /************************ start approve book details ************************/ + /*$proposal_q = db_query("SELECT * FROM {arduino_projects_blog_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid); + $proposal_data = db_fetch_object($proposal_q);*/ + $query = db_select('arduino_projects_blog_proposal'); + $query->fields('arduino_projects_blog_proposal'); + $query->condition('uid', $user->uid); + $query->orderBy('id', 'DESC'); + $query->range(0, 1); + $result = $query->execute(); + $proposal_data = $result->fetchObject(); + if (!$proposal_data) + { + drupal_set_message("Please submit a " . l('proposal', 'textbook-companion/proposal') . ".", 'error'); + drupal_goto(''); + } + if ($proposal_data->approval_status != 1 && $proposal_data->approval_status != 4 && $proposal_data->approval_status != 2) + { + switch ($proposal_data->approval_status) + { + case 0: + drupal_set_message(t('We have already received your proposal. We will get back to you soon.'), 'status'); + drupal_goto(''); + return; + break; + case 2: + drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'textbook-companion/proposal') . '.'), 'error'); + drupal_goto(''); + return; + break; + case 3: + drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'textbook-companion/proposal') . '.'), 'status'); + drupal_goto(''); + return; + break; + default: + drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error'); + drupal_goto(''); + return; + break; + } + } + /************************ end approve book details **************************/ + /* get step details */ + $step_id = arg(3); + /*$step_q = db_query("SELECT * FROM {arduino_projects_blog_step} WHERE id = %d AND preference_id = %d LIMIT 1", $step_id, $preference_data->id);*/ + $query = db_select('arduino_projects_blog_step'); + $query->fields('arduino_projects_blog_step'); + $query->condition('id', $step_id); + $query->condition('proposal_id', $proposal_data->id); + $query->range(0, 1); + $step_q = $query->execute(); + if ($step_data = $step_q->fetchObject()) + { + $return_html = '<strong>Title of the Book:</strong><br />' . $proposal_data->project_title . '<br /><br />'; + $return_html .= '<strong>Contributor Name:</strong><br />' . $proposal_data->contributor_name . '<br /><br />'; + $return_html .= '<strong>Step Number:</strong><br />' . $step_data->number . '<br /><br />'; + $return_html .= '<strong>Title of the step:</strong><br />' . $step_data->name . '<br />'; + } + else + { + drupal_set_message(t('Invalid step.'), 'error'); + drupal_goto('textbook-companion/code'); + return; + } + /* get example list */ + $example_rows = array(); + $query = db_select('arduino_projects_blog_step_information'); + $query->fields('arduino_projects_blog_step_information'); + $query->condition('step_id', $step_id); + $example_q = $query->execute(); + $example_data = $example_q->fetchObject(); + + /* approval status */ + $approval_status = ''; + switch ($example_data->approval_status) + { + case 0: + $approval_status = 'Pending'; + break; + case 1: + $approval_status = 'Approved'; + break; + case 2: + $approval_status = 'Rejected'; + break; + } + /* example files */ + $example_files = ''; + /*$example_files_q = db_query("SELECT * FROM {arduino_projects_blog_step_files} WHERE example_id = %d ORDER BY filetype", $example_data->id);*/ + $query = db_select('arduino_projects_blog_step_files'); + $query->fields('arduino_projects_blog_step_files'); + $query->condition('step_id', $step_id); + $query->orderBy('filetype', 'ASC'); + $example_files_q = $query->execute(); + while ($example_files_data = $example_files_q->fetchObject()) + { + $file_type = ''; + switch ($example_files_data->filetype) + { + case 'I': + $file_type = 'Images'; + break; + case 'G': + $file_type = 'Gifs'; + break; + default: + } + $example_files .= l($example_files_data->filename, 'textbook-companion/download/file/' . $example_files_data->id) . ' (' . $file_type . ')<br />'; + } + if ($example_data->approval_status == 0) + { + $example_rows[] = array( + 'data' => array( + $example_data->description, + // $video, + $approval_status, + $example_files, + /*l('Edit', 'textbook-companion/code/edit/' . $example_data->id) . ' | ' . l('Delete', 'textbook-companion/code/delete/' . $example_data->id, array( + 'attributes' => array( + 'onClick' => 'return confirm("Are you sure you want to delete the example?")' + ) + ))*/ + ), + 'valign' => 'top' + ); + } + else + { + $example_rows[] = array( + 'data' => array( + $example_data->description, + // $video, + $approval_status, + $example_files, + l('Download', 'textbook-companion/download/example/' . $example_data->id) + ), + 'valign' => 'top' + ); + } + if(!$example_data->video){ + $video = 'NA'; + } + else{ + $video = convertLinkToEmbed($example_data->video, 450, 350); + } + $example_header = array( + 'Description', + // 'Video', + 'Status', + 'Files', + //'Action' + ); + $return_html .= '<strong>Description:</strong><br />' . $example_data->description . '<br />'; + $return_html .= '<strong>Video:</strong><br />' . $video . '<br />'; + $return_html .= theme('table', array( + 'header' => $example_header, + 'rows' => $example_rows + )); + $return_html .= '<br />' . l('Back to step List', 'arduino-projects/code'); + return $return_html; + } + + + function all_steps_submitted_check_form($form,&$form_state,$proposal_id){ + //$form = array(); + $query = db_select('arduino_projects_blog_proposal'); + $query->fields('arduino_projects_blog_proposal'); + $query->condition('id', $proposal_id); + $query->condition('approval_status', 1); + $query->range(0, 1); + $result = $query->execute(); + $proposal_data = $result->fetchObject(); + $form['#attributes'] = array( + 'enctype' => "multipart/form-data" + ); + $form['all_steps_submitted'] = array( + '#type' => 'checkbox', + '#title' => t('I have submitted steps for the project'), + '#description' => 'Once you have submited this option you are not able to upload more steps.', + '#required' => TRUE, + ); + //var_dump($preference_data->approved_codable_example_files);die; + $form['hidden_preference_id'] = array( + '#type' => 'hidden', + '#value' => $proposal_id + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); + return $form; +} + +function all_steps_submitted_check_form_submit($form,&$form_state){ + global $user; + $query = db_select('arduino_projects_blog_proposal'); + $query->fields('arduino_projects_blog_proposal'); + $query->condition('uid', $user->uid); + $query->orderBy('id', 'DESC'); + $query->range(0, 1); + $result = $query->execute(); + $proposal_data = $result->fetchObject(); + if (!$proposal_data) + { + drupal_set_message("Please submit a " . l('proposal', 'textbook-companion/proposal') . ".", 'error'); + drupal_goto(''); + } + if ($proposal_data->approval_status != 1 && $proposal_data->approval_status != 4 && $proposal_data->approval_status != 2) + { + switch ($proposal_data->approval_status) + { + case 0: + drupal_set_message(t('We have already received your proposal. We will get back to you soon.'), 'status'); + drupal_goto(''); + return; + break; + case 2: + drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'textbook-companion/proposal') . '.'), 'error'); + drupal_goto(''); + return; + break; + case 3: + drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'textbook-companion/proposal') . '.'), 'status'); + drupal_goto(''); + return; + break; + case 5: + drupal_set_message(t('You have submmited your all codes'), 'status'); + drupal_goto(''); + return; + break; + default: + drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error'); + drupal_goto(''); + return; + break; + } + } + db_query('UPDATE arduino_projects_blog_proposal SET submitted_steps = 1 WHERE id = :proposal_id',array(':proposal_id' => $proposal_data->id)); + +}
\ No newline at end of file |