From a497165c9d776cff3abd6a7967d9a9438545184d Mon Sep 17 00:00:00 2001 From: priyankabhagwat Date: Tue, 26 Jul 2016 17:00:21 +0530 Subject: responsive layout and various changes --- fossee_stats.module | 7472 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 6638 insertions(+), 834 deletions(-) (limited to 'fossee_stats.module') diff --git a/fossee_stats.module b/fossee_stats.module index c9ff37e..ef4406b 100755 --- a/fossee_stats.module +++ b/fossee_stats.module @@ -1,913 +1,6717 @@ - array( - "title" => t("Access fossee_stats"), - "description" => t("Allows users to view job postings.") - ), - "manage fossee_stats" => array( - "title" => t("Manage fossee_stats"), - "description" => t("Allows users to manage job postings.") - ), - ); + array( + "title" => t("Access fossee_stats"), + "description" => t("Allows users to view fossee stats.") + ), + "view workshop" => array( + "title" => t("View Workshop"), + "description" => t("Allows users to view workshop.") + ), + "manage workshop" => array( + "title" => t("Manage Workshop"), + "description" => t("Allows users to manage workshop.") + ), + "view postalcampaign" => array( + "title" => t("View postalcampaign"), + "description" => t("Allows users to view postalcampaign.") + ), + "manage postalcampaign" => array( + "title" => t("Manage Postalcampaign"), + "description" => t("Allows users to manage postalcampaign.") + ), + "view tutorial" => array( + "title" => t("View Spoken Tutorial"), + "description" => t("Allows users to view spoken tutorial.") + ), + "manage tutorial" => array( + "title" => t("Manage Spoken Tutorial"), + "description" => t("Allows users to manage spoken tutorial.") + ), + "view events" => array( + "title" => t("View Events"), + "description" => t("Allows users to view events.") + ), + "manage events" => array( + "title" => t("Manage Events"), + "description" => t("Allows users to manage events.") + ), + "administer events" => array( + "title" => t("Events upload setting"), + "description" => t("Allows users to manage postalcampaign.") + ) + + ); +} + +function fossee_stats_menu() +{ + $items = array(); + //Load main page + $items["fossee-stats"] = array( + "title" => "FOSSEE STATS", + "page callback" => "drupal_get_form", + "page arguments" => array( + "fossee_stats_form" + ), + "access arguments" => array( + "access fossee_stats" + ), + "type" => MENU_NORMAL_ITEM + ); + //Fetch the list of TBC and LM which comes after filter is applied. + $items["get-list"] = array( + "title" => "", + "page callback" => "list_tbc_and_lm_detail", + 'page arguments' => array( + 8 + ), + "access arguments" => array( + "access fossee_stats" + ), + "type" => MENU_CALLBACK + ); + //Fetch the list of self workshop with all detail after filter is applied and count is received + $items['completed-workshops-list'] = array( + 'title' => '', + 'page callback' => 'completed_workshops_list', + 'page arguments' => array( + 5 + ), + "access arguments" => array( + "access fossee_stats" + ), + //'access callback' => TRUE, + "type" => MENU_CALLBACK + ); + //Fetch the Details of self workshop + $items['view-completed-workshop'] = array( + 'title' => 'Workshop Details', + 'page callback' => 'view_completed_workshop', + 'access callback' => TRUE, + ); + + //Following are menu of Events (Workshop, Conference along with testimonial and images and speakers) + + $items["events/add"] = array( + "title" => "Add Events", + "page callback" => "workshop_display_all", + "access arguments" => array( + "manage workshop" + ), + "type" => MENU_CALLBACK + ); + //To edit existing events detail + $items["events/edit"] = array( + "title" => "Edit Events", + "page callback" => "workshop_edit_all", + "access arguments" => array( + "manage workshop" + ), + "type" => MENU_CALLBACK + ); + //To delete existing events + $items["events/delete"] = array( + "title" => "Delete Events", + "page callback" => "workshop_delete_all", + "access arguments" => array( + "manage workshop" + ), + "type" => MENU_CALLBACK + ); + //List of all events + $items["events/view_details"] = array( + "title" => "Details of Selected Event", + "page callback" => "workshop_view_details_all", + "access arguments" => array( + "view workshop" + ), + "type" => MENU_CALLBACK + ); + //List of images added to particular event + $items["events/images"] = array( + "title" => "Event's Images", + "page callback" => "workshop_view_image_all", + "access arguments" => array( + "view workshop" + ), + "type" => MENU_CALLBACK + ); + //For changing image + $items["events/images/change"] = array( + "title" => "Event's Images", + "page callback" => "workshop_view_image_change", + "access arguments" => array( + "view workshop" + ), + "type" => MENU_CALLBACK + ); + //Display all testimonial added for event in list + $items["events/testimonials"] = array( + //"title" => "Testimonials", + "page callback" => "workshop_view_all_testimonials", + "access arguments" => array( + "view workshop" + ), + "type" => MENU_CALLBACK + ); + //Display details of selected testimonial + $items["events/testimonials/view"] = array( + "title" => "Testimonial", + "page callback" => "workshop_view_selected_testimonial", + "access arguments" => array( + "view workshop" + ), + "type" => MENU_CALLBACK + ); + + $items["events"] = array( + "title" => "Events", + "page callback" => "event_seminar_view_all", + "access arguments" => array( + "view events" + ), + "type" => MENU_CALLBACK + ); + + $items["testconf"] = array( + "title" => "Activities", + "page callback" => "event_activities_all", + "access arguments" => array( + "view events" + ), + "type" => MENU_CALLBACK + ); + + + // List of all Postal Campaign + $items["postalcampaign"] = array( + "title" => "Postal Campaign", + "page callback" => "postalcampaign_view_withoutfilter", + "access arguments" => array( + "view postalcampaign" + ), + "type" => MENU_CALLBACK + ); + // Add Postal Campaign + $items["postalcampaign/add"] = array( + "title" => "Add Postal Campaign", + "page callback" => "postalcampaign_display_all", + "access arguments" => array( + "manage postalcampaign" + ), + "type" => MENU_CALLBACK + ); + // Edit Postal Campaign + $items["postalcampaign/edit"] = array( + "title" => "Edit Postal Campaign", + "page callback" => "postalcampaign_edit_all", + "access arguments" => array( + "manage postalcampaign" + ), + "type" => MENU_CALLBACK + ); + // Delete Postal Campaign + $items["postalcampaign/delete"] = array( + "title" => "Delete Postal Campaign", + "page callback" => "postalcampaign_delete_all", + "access arguments" => array( + "manage postalcampaign" + ), + "type" => MENU_CALLBACK + ); + // View detail of selected Postal Campaign + $items["postalcampaign/view_details"] = array( + "title" => "Postal Campaign Detail", + "page callback" => "postalcampaign_view_details_all", + "access arguments" => array( + "view postalcampaign" + ), + "type" => MENU_CALLBACK + ); + //To download postal campaign poster in zip format + $items["postalcampaign/download"] = array( + "title" => "Download Postal Campaign", + "page callback" => "createZipOfPosterMaterial", + "access arguments" => array( + "view postalcampaign" + ), + "type" => MENU_CALLBACK + ); + + /*Spoken Tutorial*/ + + //Add Spoken Tutorial + + $items["spokentutorial/add"] = array( + "title" => "Add Spoken Tutorial", + "page callback" => "spokentutorial_display_all", + "access arguments" => array( + "view tutorial" + ), + "type" => MENU_CALLBACK + ); + + /* ADMIN SETTINGS */ + //For mentioning extension allowed for image and pdf + $items['admin/settings/events'] = array( + 'title' => 'Events Settings', + 'description' => 'Events Settings', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'events_settings_form' + ), + 'access arguments' => array( + 'administer events' + ), + 'type' => MENU_NORMAL_ITEM, + 'file' => 'settings.inc' + ); + return $items; +} + +//Folder path to save all uploaded images of events +function events_images_path() + { + return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'events_images/'; + } + +//Folder path to save all uploaded images/PDF of postal campaign +function posters_path() { + + return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'campaign_posters/'; +} + +//Main Page Form +function fossee_stats_form($form, &$form_state) +{ + /* First Dropdown for Foss type */ + + $options_first = _ajax_example_get_first_dropdown_options(); + if (isset($form_state['values']['foss_sub_project']) && isset($form_state['values']['foss_type']) && isset($form_state['values']['foss_sub_project_status'])) { + $foss_project = isset($form_state['values']['foss_type']) ? $form_state['values']['foss_type'] : key($options_first); + } else { + $foss_project = ''; + } + $form['foss_type'] = array( + '#type' => 'select', + '#prefix' => '
', + '#title' => t('FOSS Type'), + '#multiple' => false, + '#options' => $options_first, + //'#default_value' => $foss_project, + '#validated' => TRUE, + '#ajax' => array( + 'callback' => 'ajax_foss_type_dependent_dropdown_callback', + 'wrapper' => 'dropdown-second-replace', + 'progress' => array( + 'message' => '' + ) + ) + ); + /* Second Dropdown for Activities like TBC, LM and other */ + + if (isset($form_state['values']['foss_sub_project']) && isset($form_state['values']['foss_type']) && isset($form_state['values']['foss_sub_project_status'])) { + $foss_sub_project = isset($form_state['values']['foss_sub_project']) ? $form_state['values']['foss_sub_project'] : key(get_activities_list($foss_project)); + } else { + $foss_sub_project = ''; + } + $form['foss_sub_project'] = array( + '#type' => 'select', + '#title' => t('Activities'), + '#options' => get_activities_list($foss_project), + '#prefix' => '', + '#default_value' => $foss_sub_project_status, + '#validated' => TRUE, + '#states' => array( + 'invisible' => array( + array( + array( + ':input[name="foss_sub_project"]' => array( + 'value' => 0 + ) + ), + 'or', + array( + ':input[name="foss_type"]' => array( + 'value' => "" + ) + + ) + ) + ) + ) + ); + /* Start Date for Filter */ + $form['start_date'] = array( + '#type' => 'date_popup', + '#title' => t('From Date:'), + '#date_label_position' => '', + '#description' => '', + '#default_value' => '', + '#date_format' => 'Y-m-d', + '#date_increment' => 0, + '#date_year_range' => '2011:+0', + '#prefix' => '', + '#datepicker_options' => array( + 'maxDate' => 0 + ), + '#states' => array( + 'invisible' => array( + ':input[name="foss_type"]' => array( + 'value' => "" + ) + ) + ) + ); + /* End Date for Filter */ + $form['end_date'] = array( + '#type' => 'date_popup', + '#title' => t('To Date:'), + '#date_label_position' => '', + '#description' => '', + '#default_value' => '', + '#date_format' => 'Y-m-d', + '#date_increment' => 0, + '#date_year_range' => '2011:+0', + '#prefix' => '', + '#datepicker_options' => array( + 'maxDate' => 0 + ), + '#states' => array( + 'invisible' => array( + ':input[name="foss_type"]' => array( + 'value' => "" + ) + ) + ) + ); + /* Country list for Filter */ + if (isset($form_state['values']['countryname']) && isset($form_state['values']['statename']) && isset($form_state['values']['cityname'])) { + $countryname = isset($form_state['values']['countryname']) ? $form_state['values']['countryname'] : key(get_country_list($foss_project, $foss_sub_project)); + } else { + $countryname = ''; + } + $form['countryname'] = array( + "#type" => "select", + "#title" => t("Select Country"), + '#prefix' => '', + '#options' => get_country_list($foss_project, $foss_sub_project), + '#states' => array( + 'invisible' => array( + array( + array( + ':input[name="foss_sub_project"]' => array( + 'value' => 0 + ) + ), + 'or', + array( + ':input[name="foss_type"]' => array( + 'value' => "" + ), + ':input[name="foss_type"]' => array( + 'value' => 3 + ) + + ) + ) + ) + ), + '#ajax' => array( + 'callback' => 'ajax_state_list_dependent_dropdown_callback', + 'wrapper' => 'load_state', + 'progress' => array( + 'message' => '' + ) + ) + ); + + /* State list for Filter */ + if (isset($form_state['values']['countryname']) && isset($form_state['values']['statename']) && isset($form_state['values']['cityname'])) { + $statename = isset($form_state['values']['statename']) ? $form_state['values']['statename'] : key(get_state_list($foss_project, $foss_sub_project, $countryname)); + } else { + $statename = ''; + } + + $form['statename'] = array( + "#type" => "select", + "#title" => t("State Name"), + '#validated' => TRUE, + '#options' => get_state_list($foss_project, $foss_sub_project, $countryname), + '#prefix' => '', + '#states' => array( + 'invisible' => array( + array( + array( + ':input[name="foss_sub_project"]' => array( + 'value' => 0 + ) + ), + 'or', + array( + ':input[name="foss_type"]' => array( + 'value' => "" + ), + ':input[name="foss_type"]' => array( + 'value' => 3 + ) + + ) + ) + ) + ), + '#ajax' => array( + 'callback' => 'ajax_city_list_dependent_dropdown_callback', + 'wrapper' => 'load_state', + 'progress' => array( + 'message' => '' + ) + ) + ); + +/* City list for Filter */ + if (isset($form_state['values']['countryname']) && isset($form_state['values']['statename']) && isset($form_state['values']['cityname'])) { + $cityname = isset($form_state['values']['cityname']) ? $form_state['values']['cityname'] : key(get_city_list($foss_project, $foss_sub_project, $countryname, $statename)); + } else { + $cityname = ''; + } + $form['cityname'] = array( + "#type" => "select", + "#title" => t("City Name"), + '#validated' => TRUE, + '#options' => get_city_list($foss_project, $foss_sub_project, $countryname, $statename), + '#prefix' => '', + '#states' => array( + 'invisible' => array( + array( + array( + ':input[name="foss_sub_project"]' => array( + 'value' => 0 + ) + ), + 'or', + array( + ':input[name="foss_type"]' => array( + 'value' => "" + ), + ':input[name="foss_type"]' => array( + 'value' => 3 + ) + + ) + ) + ) + ) + ); + $form['submit'] = array( + '#type' => 'submit', + '#ajax' => array( + 'callback' => 'ajax_example_submit_driven_callback', + 'progress' => array( + 'message' => '' + ) + ), + '#value' => t('Filter'), + '#prefix' => '
', + '#suffix' => '', + '#default_value' => "--------------", + '#validated' => TRUE, + '#ajax' => array( + 'callback' => 'ajax_foss_sub_project_dependent_dropdown_callback', + 'wrapper' => 'dropdown-third-replace', + 'progress' => array( + 'message' => '' + ) + ), + + '#states' => array( + 'invisible' => array( + ':input[name="foss_type"]' => array( + 'value' => "" + ) + ) + ) + ); + + /* third Dropdown for Status like Completed and In Progress */ + if (isset($form_state['values']['foss_sub_project']) && isset($form_state['values']['foss_type']) && isset($form_state['values']['foss_sub_project_status'])) { + $foss_sub_project_status = isset($form_state['values']['$foss_sub_project_status']) ? $form_state['values']['$foss_sub_project_status'] : ''; + } else { + $foss_sub_project_status = ''; + } + $form['foss_sub_project_status'] = array( + '#type' => 'select', + '#title' => t('Status'), + '#options' => _ajax_example_get_third_dropdown_options($foss_sub_project), + '#prefix' => '
', + '#suffix' => '
', + '#suffix' => '
', + '#suffix' => '
', + '#suffix' => '
', + '#suffix' => '
', + '#suffix' => '' + ); + $form['reset'] = array( + '#type' => 'submit', + '#value' => t('Reset'), + '#prefix' => '', + '#suffix' => '
' + ); + //This is used for displaying text (tab sta) + $form['displaytext'] = array( + '#type' => 'markup', + '#prefix' => '
', + '#suffix' => '
', + '#markup' => '' + ); + //For displaying count of TBC of all foss + $form['tbctable'] = array( + '#type' => 'item', + '#prefix' => '
', + '#markup' => '' + ); + $TBC_getchart = getchart("TBC"); + $LM_getchart = getchart("LM"); + $form['tab_content'] = array( + '#type' => 'item', + '#markup' => '
+ +
' . get_tabledata_TBC_or_LM("TBC", "1960/01/01", "").' +
' . drupal_render($TBC_getchart) . '
+
+ +
' . get_tabledata_TBC_or_LM("LM", "1960/01/01", "").' +
' . drupal_render($LM_getchart) . '
+
+ +
' . workshop_view_all(0,1960-01-01, date("Y-m-d")).'
+ +
'.getselfworkshoplcount(0,1960-01-01, date("Y-m-d"),"","").'
+ +
' . conference_seminar_view_all(0, "", "").'
+ +
'.spokentutorial_view_all("").'
+
' + ); + $form['lastdiv'] = array( + '#type' => 'item', + '#markup' => '', + '#suffix' => '
' + ); + return $form; +} + +/* This function is used to create chart for TBC/LM */ +function getchart($sub_type) +{ + $title = ""; + if ($sub_type == "TBC") { + $title = "Textbook Companion Statictics"; + } else { + $title = "Lab Migration Statistics"; + } + $chart = array( + '#type' => 'chart', + '#title' => t($title), + '#chart_type' => 'pie', + '#chart_library' => 'google', + '#legend_position' => 'right', + '#data_labels' => TRUE, + '#tooltips' => TRUE, + '#width' => 700, + '#height' => 300 + ); + $chart['pie_data'] = array( + '#type' => 'chart_data', + '#title' => t($title), + '#data' => get_data_for_chart_allproject($sub_type) + ); + $example['chart'] = $chart; + return $example; +} + +//This is used to create a bar chart for particular LM or TBC and along with filters +function getchartforselectedProject($foss_type, $sub_type, $startdate, $enddate, $countryname, $statename, $cityname) +{ + + $title = ""; + if ($sub_type == "TBC") { + $title = $foss_type . "" . "'s Textbook Companion Statictics"; + } else { + $title = $foss_type . "" . "'s Lab Migration Statistics"; + } + + $chart = array( + '#type' => 'chart', + '#title' => t($title), + '#chart_type' => 'column', + '#chart_library' => 'google', + '#legend_position' => 'bottom', + '#data_labels' => TRUE, + '#tooltips' => TRUE, + '#width' => 800, + '#height' => 300 + ); + $chart['pie_data'] = array( + '#type' => 'chart_data', + '#title' => t($title), + '#data' => get_data_for_chart_selectedproject($foss_type, $sub_type, $startdate, $enddate, $countryname, $statename, $cityname) + ); + $example['chart'] = $chart; + return $example; +} + + +//This is used to create a pie chart for particular LM or TBC and along with filters +function getpiechartforselectedProject($foss_type, $sub_type, $startdate, $enddate, $countryname, $statename, $cityname) +{ + + $title = ""; + if ($sub_type == "TBC") { + $title = $foss_type . "" . "'s Textbook Companion Statictics"; + } else { + $title = $foss_type . "" . "'s Lab Migration Statistics"; + } + $chart = array( + '#type' => 'chart', + '#title' => t($title), + '#chart_type' => 'pie', + '#chart_library' => 'google', + '#legend_position' => 'right', + '#data_labels' => TRUE, + '#tooltips' => TRUE, + '#width' => 700, + '#height' => 300 + ); + $chart['pie_data'] = array( + '#type' => 'chart_data', + '#title' => t($title), + '#data' => get_data_for_chart_selectedproject($foss_type, $sub_type, $startdate, $enddate, $countryname, $statename, $cityname) + ); + $example['chart'] = $chart; + return $example; +} + + +//Function is used to get the count of LM or TBC for all foss type and pass this count to create charts +function get_data_for_chart_allproject($sub_type) +{ + $rows = array(); + if ($sub_type == "TBC") { + $query = db_select('foss_type'); + $query->fields('foss_type', array( + 'id' + )); + $query->fields('foss_type', array( + 'foss_name' + )); + $query->fields('foss_type', array( + 'tbc' + )); + $query->condition('tbc', 1); + $result = $query->execute(); + while ($foss_detail = $result->fetchObject()) { + if ($foss_detail->foss_name != null) { + if ($foss_detail->foss_name != 'Python') { + db_set_active($foss_detail->foss_name); //Active other database + //For TBC + if ($foss_detail->foss_name != 'eSim' && $foss_detail->foss_name != 'OpenFOAM' && $foss_detail->foss_name != 'OR-Tools') { + $query2 = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND pe.category>0"); + } else { + $query2 = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1"); + } + db_set_active('default'); // We need to call the main (drupal) db back + db_set_active(); + $completedbookcount = $query2->fetchObject()->book_count; + $option1 = array( + $foss_detail->foss_name, + (int) $completedbookcount + ); + array_push($rows, $option1); + } else { + db_set_active($foss_detail->foss_name); //Active other database + $query2 = db_select('tbc_book'); + $query2->addExpression('count(*)', 'count'); + $query2->condition('approved', 1); + $result2 = $query2->execute(); + db_set_active('default'); // We need to call the main (drupal) db back + db_set_active(); + $completedbookcount = $result2->fetchObject()->count; + $option1 = array( + $foss_detail->foss_name, + (int) $completedbookcount + ); + array_push($rows, $option1); + } + } + } + } else { + $query = db_select('foss_type'); + $query->fields('foss_type', array( + 'id' + )); + $query->fields('foss_type', array( + 'foss_name' + )); + $query->fields('foss_type', array( + 'lab_migration' + )); + $query->condition('lab_migration', 1); + $result = $query->execute(); + while ($foss_detail = $result->fetchObject()) { + if ($foss_detail->foss_name != null) { + db_set_active($foss_detail->foss_name); //Active other database + //For LM + $query3 = db_select('lab_migration_proposal'); + $query3->addExpression('count(*)', 'count'); + $query3->condition('approval_status', 3); + $result3 = $query3->execute(); + db_set_active('default'); // We need to call the main (drupal) db back + db_set_active(); + $completedlabcount = $result3->fetchObject()->count; + $option1 = array( + $foss_detail->foss_name, + (int) $completedlabcount + ); + array_push($rows, $option1); + } + } + } + return $rows; +} + +//This function is used to get list of TBC books/LM Labs after the filter is applied +function list_tbc_and_lm_detail($String, $foss_type, $sub_type, $status, $startdate, $enddate, $countryname, $statename, $cityname) +{ + + if ($cityname == "" || $cityname == "null") { + $cityname = "%"; + } else { + $cityname = $cityname; + } + if ($statename == "" || $statename == "null") { + $statename = "%"; + } else { + $statename = $statename; + } + if ($countryname == "" || $countryname == "null") { + $countryname = "%"; + } else { + $countryname = $countryname; + } + + $flag = 1; + $page_content = ""; + db_set_active($foss_type); + $query2 = ""; + if ($sub_type == "TBC") { + + if ($foss_type != null) { + if ($foss_type != 'Python') { + //For TBC + if ($foss_type != 'eSim' && $foss_type != 'OpenFOAM' && $foss_type != 'OR-Tools') { + if ($foss_type != 'DWSIM') { + if ($status == "completed") { + $query2 = db_query("SELECT pe.book as book,pe.author as author,pe.publisher as publisher,pe.year as year,pe.id as id FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND pe.category>0 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + + } + if ($status == "pending") { + $query2 = db_query("SELECT pe.book,pe.author,pe.publisher,pe.year,pe.id FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status !=3 AND pe.approval_status =1 AND pe.category>0 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + $flag = 0; + } + } else { + if ($status == "completed") { + $query2 = db_query("SELECT pe.book,pe.author,pe.publisher,pe.year,pe.id FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND pe.category>0 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate ", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + } + if ($status == "pending") { + $query2 = db_query("SELECT pe.book,pe.author,pe.publisher,pe.year,pe.id FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status !=3 AND pe.approval_status =1 AND pe.category>0 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + $flag = 0; + } + } + } else { + if ($status == "completed") { + $query2 = db_query("SELECT pe.book,pe.author,pe.publisher,pe.year,pe.id FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + } + if ($status == "pending") { + $query2 = db_query("SELECT pe.book,pe.author,pe.publisher,pe.year,pe.id FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status !=3 AND pe.approval_status =1 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + $flag = 0; + } + } + + } else { + if ($status == "completed") { + $query2 = db_select('tbc_book', 'tbc'); + $query2->fields('tbc', array( + 'title', + 'author', + 'id' + )); + $query2->condition('approved', 1); + + } + if ($status == "pending") { + $query2 = db_select('tbc_book', 'tbc'); + $query2->fields('tbc', array( + 'title', + 'author', + 'id' + )); + $query2->condition('approved', 1, '<>'); + + } + + } + } + db_set_active('default'); // We need to call the main (drupal) db back + db_set_active(); + if ($flag != 0) { + $page_content .= "

List of Completed Books


"; + $query = db_select('foss_type'); + $query->fields('foss_type', array( + 'id' + )); + $query->fields('foss_type', array( + 'tbc_run' + )); + $query->condition('tbc', 1); + $query->condition('foss_name', $foss_type); + $result = $query->execute(); + $foss_detail = $result->fetchObject(); + $page_content .= "
    "; + $i = 1; + while ($preference_data = $query2->fetchObject()) { + $page_content .= "
  1. " . $i++ . ". "; + $page_content .= "id . " target='_blank'>" . $preference_data->book . " by " . $preference_data->author . ", " . $preference_data->publisher . ", " . $preference_data->year . ""; + + + $page_content .= "
  2. "; + } + $page_content .= "
"; + + } else { + $page_content .= "

List of Books in Progress


"; + $page_content .= "
    "; + $i = 1; + while ($preference_data = $query2->fetchObject()) { + $page_content .= "
  1. " . $i++ . ". "; + $page_content .= $preference_data->book . " by " . $preference_data->author . ", " . $preference_data->publisher . ", " . $preference_data->year; + $page_content .= "
  2. "; + } + $page_content .= "
"; + } + + } else { + + if ($foss_type != null) { + + if ($status == "completed") { + $query2 = db_query("SELECT * from lab_migration_proposal WHERE approval_status=3 AND city LIKE :city AND state LIKE :state AND country LIKE :country AND FROM_UNIXTIME(approval_date) >=:startdate AND FROM_UNIXTIME(approval_date) <=:enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + } + if ($status == "pending") { + $query2 = db_query("SELECT * from lab_migration_proposal WHERE approval_status=1 AND city LIKE :city AND state LIKE :state AND country LIKE :country AND FROM_UNIXTIME(approval_date) >=:startdate AND FROM_UNIXTIME(approval_date) <=:enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + $flag = 0; + } + db_set_active('default'); // We need to call the main (drupal) db back + db_set_active(); + if ($flag != 0) { + $page_content .= "

List of Completed Labs


"; + $query = db_select('foss_type'); + $query->fields('foss_type', array( + 'id' + )); + $query->fields('foss_type', array( + 'lm_run' + )); + $query->condition('lab_migration', 1); + $query->condition('foss_name', $foss_type); + $result = $query->execute(); + $foss_detail = $result->fetchObject(); + $page_content .= "
    "; + $i = 1; + while ($row = $query2->fetchObject()) { + $page_content .= "
  1. " . $i++ . ". "; + $approval_date = date("Y", $row->approval_date); + $page_content .= "id . " target='_blank'>" . $row->lab_title . " " . $approval_date . " (Proposed by " . $row->name . ") "; + //$page_content .= l($row->lab_title . " " . $approval_date,$foss_detail->lm_run."/". $row->id); + $page_content .= "
  2. "; + } + $page_content .= "
"; + } else { + $page_content .= "

List of Labs in Progress


"; + $page_content .= "
    "; + $i = 1; + while ($row = $query2->fetchObject()) { + $page_content .= "
  1. " . $i++ . ". "; + $approval_date = date("Y", $row->approval_date); + $page_content .= $row->lab_title . " " . $approval_date . " (Proposed by " . $row->name . ")"; + $page_content .= "
  2. "; + } + $page_content .= "
"; + } + + } + + } + db_set_active('default'); // We need to call the main (drupal) db back + db_set_active(); + + return $page_content; +} + +/* This function is used to get count of LM and TBC after a filter is applied and pass this count to create chart function*/ +function get_data_for_piechart_selectedproject($foss_type, $sub_type, $startdate, $enddate, $countryname, $statename, $cityname) +{ + + if ($enddate == "") { + $enddate = date("Y-m-d"); + } + $rows = array(); + if ($sub_type == "TBC") { + $query = db_select('foss_type'); + $query->fields('foss_type', array( + 'id' + )); + $query->fields('foss_type', array( + 'foss_name' + )); + $query->fields('foss_type', array( + 'tbc' + )); + $query->condition('tbc', 1); + $query->condition('foss_name', $foss_type); + $result = $query->execute(); + $foss_detail = $result->fetchObject(); + if ($foss_detail->foss_name != null) { + if ($foss_detail->foss_name != 'Python') { + $rows = array(); + db_set_active($foss_detail->foss_name); //Active other database + //For TBC + if ($foss_detail->foss_name != 'eSim' && $foss_detail->foss_name != 'OpenFOAM' && $foss_detail->foss_name != 'OR-Tools') { + if ($foss_detail->foss_name != 'DWSIM') { + $query2 = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND pe.category>0 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + $query3 = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status !=3 AND pe.approval_status =1 AND pe.category>0 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + } else { + $query2 = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND pe.category>0 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate ", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + $query3 = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status !=3 AND pe.approval_status =1 AND pe.category>0 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + } + } else { + $query2 = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + $query3 = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status !=3 AND pe.approval_status =1 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + } + db_set_active('default'); // We need to call the main (drupal) db back + db_set_active(); + $completedbookcount = $query2->fetchObject()->book_count; + $pendingbookcount = $query3->fetchObject()->book_count; + $option1 = array( + "Completed TBC", + (int) $completedbookcount + ); + array_push($rows, $option1); + $option2 = array( + "In Progress TBC", + (int) $pendingbookcount + ); + array_push($rows, $option2); + } else { + $rows = array(); + db_set_active($foss_detail->foss_name); //Active other database + $query2 = db_select('tbc_book'); + $query2->addExpression('count(*)', 'count'); + //$query2->condition('author', '%'.$extrafilter.'%', 'LIKE'); + $query2->condition('approved', 1); + $result2 = $query2->execute(); + $query3 = db_select('tbc_book'); + $query3->addExpression('count(*)', 'count'); + //$query3->condition('author', '%'.$extrafilter.'%', 'LIKE'); + $query3->condition('approved', 1, '<>'); + $result3 = $query3->execute(); + db_set_active('default'); // We need to call the main (drupal) db back + db_set_active(); + $completedbookcount = $result2->fetchObject()->count; + $pendingbookcount = $result3->fetchObject()->count; + $option1 = array( + "Completed TBC", + (int) $completedbookcount + ); + array_push($rows, $option1); + $option2 = array( + "In Progress TBC", + (int) $pendingbookcount + ); + array_push($rows, $option2); + } + } + } else { + $rows = array(); + $query = db_select('foss_type'); + $query->fields('foss_type', array( + 'id' + )); + $query->fields('foss_type', array( + 'foss_name' + )); + $query->fields('foss_type', array( + 'lab_migration' + )); + $query->condition('lab_migration', 1); + $query->condition('foss_name', $foss_type); + $result = $query->execute(); + $foss_detail = $result->fetchObject(); + if ($foss_detail->foss_name != null) { + db_set_active($foss_detail->foss_name); //Active other database + //For LM + $query3 = db_query("SELECT COUNT(*) AS count from lab_migration_proposal WHERE approval_status=3 AND city LIKE :city AND state LIKE :state AND country LIKE :country AND FROM_UNIXTIME(approval_date) >=:startdate AND FROM_UNIXTIME(approval_date) <=:enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + $query4 = db_query("SELECT COUNT(*) AS count from lab_migration_proposal WHERE approval_status=1 AND city LIKE :city AND state LIKE :state AND country LIKE :country AND FROM_UNIXTIME(approval_date) >=:startdate AND FROM_UNIXTIME(approval_date) <=:enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + db_set_active('default'); // We need to call the main (drupal) db back + db_set_active(); + $completedlabcount = $query3->fetchObject()->count; + $pendinglabcount = $query4->fetchObject()->count; + $option1 = array( + "Completed Labs", + (int) $completedlabcount + ); + array_push($rows, $option1); + $option2 = array( + "In Progress labs", + (int) $pendinglabcount + ); + array_push($rows, $option2); + } + } + return $rows; +} + + + + +/* This function is used to get count of LM and TBC after a filter is applied and pass this count to create chart function*/ +function get_data_for_chart_selectedproject($foss_type, $sub_type, $startdate, $enddate, $countryname, $statename, $cityname) +{ + + if ($enddate == "") { + $enddate = date("Y-m-d"); + } + $rows = array(); + if ($sub_type == "TBC") { + $query = db_select('foss_type'); + $query->fields('foss_type', array( + 'id' + )); + $query->fields('foss_type', array( + 'foss_name' + )); + $query->fields('foss_type', array( + 'tbc' + )); + $query->condition('tbc', 1); + $query->condition('foss_name', $foss_type); + $result = $query->execute(); + $foss_detail = $result->fetchObject(); + if ($foss_detail->foss_name != null) { + if ($foss_detail->foss_name != 'Python') { + $rows = array(); + db_set_active($foss_detail->foss_name); //Active other database + //For TBC + if ($foss_detail->foss_name != 'eSim' && $foss_detail->foss_name != 'OpenFOAM' && $foss_detail->foss_name != 'OR-Tools') { + if ($foss_detail->foss_name != 'DWSIM') { + $query2 = db_query("SELECT COUNT( pe.book ) AS book_count ,FROM_UNIXTIME(po.completion_date, '%Y') AS year FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND pe.category>0 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate Group by FROM_UNIXTIME(po.completion_date, '%Y')", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + /* $query3 = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status !=3 AND pe.approval_status =1 AND pe.category>0 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + ));*/ + } else { + $query2 = db_query("SELECT COUNT( pe.book ) AS book_count ,FROM_UNIXTIME(po.completion_date, '%Y') AS year FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND pe.category>0 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate Group by FROM_UNIXTIME(po.completion_date, '%Y')", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + /* $query3 = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status !=3 AND pe.approval_status =1 AND pe.category>0 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + ));*/ + } + } else { + $query2 = db_query("SELECT COUNT( pe.book ) AS book_count, FROM_UNIXTIME(po.completion_date, '%Y') AS year FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate Group by FROM_UNIXTIME(po.completion_date, '%Y')", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + /*$query3 = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status !=3 AND pe.approval_status =1 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + ));*/ + } + db_set_active('default'); // We need to call the main (drupal) db back + db_set_active(); + + $result = $query2->fetchAll(); + + foreach ($result as $tbc_yearwise_count) { + + $completedbookcount= $tbc_yearwise_count->book_count; + $option1 = array( + $tbc_yearwise_count->year, + (int) $completedbookcount + ); + array_push($rows, $option1); + } + /* while ($tbc_yearwise_count = $result->fetchObject()) { + $completedbookcount= $tbc_yearwise_count->book_count; + $option1 = array( + $tbc_yearwise_count->year, + (int) $completedbookcount + ); + array_push($rows, $option1); + + }*/ + + + //$completedbookcount = $query2->fetchObject()->book_count; + + //$pendingbookcount = $query3->fetchObject()->book_count; + /*$option1 = array( + "Completed TBC", + (int) $completedbookcount + ); + array_push($rows, $option1);*/ + /* $option2 = array( + "In Progress TBC", + (int) $pendingbookcount + ); + array_push($rows, $option2);*/ + } else { + $rows = array(); + db_set_active($foss_detail->foss_name); //Active other database + $query2 = db_select('tbc_book'); + $query2->addExpression('count(*)', 'count'); + //$query2->condition('author', '%'.$extrafilter.'%', 'LIKE'); + $query2->condition('approved', 1); + $result2 = $query2->execute(); + + /*$query3 = db_select('tbc_book'); + $query3->addExpression('count(*)', 'count'); + //$query3->condition('author', '%'.$extrafilter.'%', 'LIKE'); + $query3->condition('approved', 1, '<>'); + $result3 = $query3->execute();*/ + db_set_active('default'); // We need to call the main (drupal) db back + db_set_active(); + $completedbookcount = $result2->fetchObject()->count; + //$pendingbookcount = $result3->fetchObject()->count; + $option1 = array( + "Completed TBC", + (int) $completedbookcount + ); + array_push($rows, $option1); + /*$option2 = array( + "In Progress TBC", + (int) $pendingbookcount + ); + array_push($rows, $option2);*/ + } + } + } else { + $rows = array(); + $query = db_select('foss_type'); + $query->fields('foss_type', array( + 'id' + )); + $query->fields('foss_type', array( + 'foss_name' + )); + $query->fields('foss_type', array( + 'lab_migration' + )); + $query->condition('lab_migration', 1); + $query->condition('foss_name', $foss_type); + $result = $query->execute(); + $foss_detail = $result->fetchObject(); + if ($foss_detail->foss_name != null) { + db_set_active($foss_detail->foss_name); //Active other database + //For LM + $query3 = db_query("SELECT COUNT(*) AS count ,FROM_UNIXTIME(approval_date, '%Y') AS year from lab_migration_proposal WHERE approval_status=3 AND city LIKE :city AND state LIKE :state AND country LIKE :country AND FROM_UNIXTIME(approval_date) >=:startdate AND FROM_UNIXTIME(approval_date) <=:enddate group by FROM_UNIXTIME(approval_date, '%Y')", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + /* $query4 = db_query("SELECT COUNT(*) AS count from lab_migration_proposal WHERE approval_status=1 AND city LIKE :city AND state LIKE :state AND country LIKE :country AND FROM_UNIXTIME(approval_date) >=:startdate AND FROM_UNIXTIME(approval_date) <=:enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + ));*/ + db_set_active('default'); // We need to call the main (drupal) db back + db_set_active(); + + $result = $query3->fetchAll(); + + foreach ($result as $lm_yearwise_count) { + + $completedlabcount= $lm_yearwise_count->count; + $option1 = array( + $lm_yearwise_count->year, + (int) $completedlabcount + ); + array_push($rows, $option1); + } + + /*$result = $query3->execute(); + + while ($lm_yearwise_count = $result->fetchObject()) { + $completedlabcount= $lm_yearwise_count->count; + $option1 = array( + $lm_yearwise_count->year, + (int) $completedlabcount + ); + array_push($rows, $option1); + + }*/ + + /*$completedlabcount = $query3->fetchObject()->count; + //$pendinglabcount = $query4->fetchObject()->count; + $option1 = array( + "Completed Labs", + (int) $completedlabcount + ); + array_push($rows, $option1);*/ + /*$option2 = array( + "In Progress labs", + (int) $pendinglabcount + ); + array_push($rows, $option2);*/ + } + } + return $rows; +} + + + + + + + + + + + +//List of option to fill first drop down ie. Foss type. +function _ajax_example_get_first_dropdown_options() +{ + $query = db_select('foss_type'); + $query->fields('foss_type', array( + 'id' + )); + $query->fields('foss_type', array( + 'foss_name' + )); + $result = $query->execute(); + $options = array(); + $options[''] = "--------------"; + while ($foss_detail = $result->fetchObject()) { + $options[$foss_detail->id] = $foss_detail->foss_name; + } + return $options; +} + +//List of option to fill secong drop down ie. Activities +/*function _ajax_example_get_second_dropdown_options($foss_project = '') +{ + if ($foss_project != NULL) { + $query = db_select('foss_type'); + $query->fields('foss_type', array( + 'tbc', + 'lab_migration', + 'workshop', + 'self_workshop', + 'conference' + )); + $query->fields('foss_type', array( + 'spoken_tutorial', + 'postal_campaigns' + )); + $query->condition('id', $foss_project); + $result = $query->execute(); + $subproject_detail = $result->fetchObject(); + $optiondata = array( + "tbc", + "lab_migration", + "workshop", + "self_workshop", + "conference", + "spoken_tutorial", + "postal_campaigns" + ); + $optionvalue = array( + " ", + "Textbook Companion", + "Lab Migration", + "Workshop", + "Self Workshop", + "Conference", + "Spoken Tutorial", + "Postal Campaigns" + ); + $options = array(); + $options[0] = "--------------"; + $i = 0; + foreach ($optiondata as $value) { + $i++; + if (($subproject_detail->$value) != 0) { + $options[$i] = $optionvalue[$i]; + } + } + return $options; + } else { + $options[0] = "--------------"; + return $options; + } +}*/ + +//List of option to fill secong drop down ie. Activities +function get_activities_list($foss_project) +{ + if ($foss_project != NULL) { + $query = db_select('foss_type'); + $query->fields('foss_type', array( + 'tbc', + 'lab_migration', + 'workshop', + 'self_workshop', + 'conference' + )); + $query->fields('foss_type', array( + 'spoken_tutorial', + 'postal_campaigns' + )); + $query->condition('id', $foss_project); + $result = $query->execute(); + $subproject_detail = $result->fetchObject(); + $optiondata = array( + "tbc", + "lab_migration", + "workshop", + "self_workshop", + "conference", + "spoken_tutorial", + "postal_campaigns" + ); + $optionvalue = array( + " ", + "Textbook Companion", + "Lab Migration", + "Workshop", + "Self Workshop", + "Conference", + "Spoken Tutorial", + "Postal Campaigns" + ); + $options = array(); + $options[0] = "--------------"; + $i = 0; + foreach ($optiondata as $value) { + $i++; + if (($subproject_detail->$value) != 0) { + $options[$i] = $optionvalue[$i]; + } + } + return $options; + } else { + $options[0] = "--------------"; + return $options; + } + +} + + +//This is used to populate dropdown third ie Status but it will fill if activity selected is either TBC or LM +function _ajax_example_get_third_dropdown_options($foss_sub_project) +{ + $options = array(); + if ($foss_sub_project != 0) { + if ($foss_sub_project == 1) { + $options[0] = "--------------"; + $options[1] = "Books in Progress"; + $options[2] = "Completed Books"; + } else if ($foss_sub_project == 2) { + $options[0] = "--------------"; + $options[1] = "Labs in Progress"; + $options[2] = "Completed Labs"; + } + } + return $options; +} + +//this is ajax callback method for first dropdown ie FOSS type +function ajax_foss_type_dependent_dropdown_callback($form, &$form_state) +{ + + $foss_sub_project = $form_state['values']['foss_type']; + $foss_sub_project_activities = $form_state['values']['foss_sub_project']; + $startdate = $form_state['values']['start_date']; + $enddate = $form_state['values']['end_date']; + $enddate = trim($enddate); + $startdate = trim($startdate); + if ($startdate == "") { + $startdate = '1960/01/01'; + } else { + $startdate = $startdate; + } + if ($enddate == "") { + $enddate = date("Y-m-d"); + } else { + $enddate = $enddate; + } + if ($foss_sub_project == "") { + $form['default_load']['#markup'] = ' + + +
+ +
' . get_tabledata_TBC_or_LM("TBC", $startdate, $enddate) . ' +
' . drupal_render(getchart("TBC")). '
+
+ +
' . get_tabledata_TBC_or_LM("LM", $startdate, $enddate) . ' +
' . drupal_render(getchart("LM")) . '
+
+ +
' . workshop_view_all(0, $startdate, $enddate) . '
+ +
'.getselfworkshoplcount(0,$startdate,$enddate,"","").'
+ +
' . conference_seminar_view_all(0, $startdate, $enddate) .'
+ +
'.spokentutorial_view_all("").'
+
'; + $commands[] = ajax_command_html("#default_load", drupal_render($form['default_load'])); + $form['load_city']['#markup'] = ""; + $commands[] = ajax_command_html("#load_city", ""); + $form['load_state']['#markup'] = ""; + $commands[] = ajax_command_html("#load_state", ""); + $form['load_country']['#markup'] = ""; + $commands[] = ajax_command_html("#load_country", ""); + $form['startdate']['#markup'] = ""; + $commands[] = ajax_command_html("#startdate", ""); + $form['enddate']['#markup'] = ""; + $commands[] = ajax_command_html("#enddate", ""); + $form['dropdown-third-replace']['#markup'] = ""; + $commands[] = ajax_command_html("#dropdown-third-replace", ""); + + } else if ($foss_sub_project == '3') { + $form['startdate']['#markup'] = ""; + $commands[] = ajax_command_html("#startdate", ""); + $form['enddate']['#markup'] = ""; + $commands[] = ajax_command_html("#enddate", ""); + $form['load_city']['#markup'] = ""; + $commands[] = ajax_command_html("#load_city", ""); + $form['load_state']['#markup'] = ""; + $commands[] = ajax_command_html("#load_state", ""); + $form['load_country']['#markup'] = ""; + $commands[] = ajax_command_html("#load_country", ""); + } + + else { + $form['start_date']['#type'] = "date_popup"; + $form['start_date']['#title'] = t('From Date:'); + $form['start_date']['#date_label_position'] = 'within'; + $form['start_date']['#description'] = ''; + $form['start_date']['#default_value'] = ''; + $form['start_date']['#date_format'] = 'Y-m-d'; + $form['start_date']['#date_increment'] = 0; + $form['start_date']['#date_year_range'] = '2011:+0'; + $form['start_date']['#datepicker_options'] = array( + 'maxDate' => 0 + ); + $commands[] = ajax_command_html("#startdate", drupal_render($form['start_date'])); + $form['end_date']['#type'] = "date_popup"; + $form['end_date']['#title'] = t('To Date:'); + $form['end_date']['#date_label_position'] = ''; + $form['end_date']['#description'] = ''; + $form['end_date']['#default_value'] = ''; + $form['end_date']['#date_format'] = 'Y-m-d'; + $form['end_date']['#date_increment'] = 0; + $form['end_date']['#date_year_range'] = '2011:+0'; + $form['end_date']['#datepicker_options'] = array( + 'maxDate' => 0 + ); + $commands[] = ajax_command_html("#enddate", drupal_render($form['end_date'])); + + } + $form['foss_sub_project']['#default_value'] = "--------------"; + $form['foss_sub_project']['#options'] = get_activities_list($foss_sub_project); + $commands[] = ajax_command_replace("#dropdown-second-replace", drupal_render($form['foss_sub_project'])); + + + if ($foss_sub_project != "" && ($foss_sub_project_activities == 1 || $foss_sub_project_activities == 2)) { + $form['foss_sub_project_status']['#type'] = "select"; + $form['foss_sub_project_status']['#title'] = t("Status"); + $form['foss_sub_project_status']['#options'] = _ajax_example_get_third_dropdown_options($foss_sub_project_activities); + $commands[] = ajax_command_html("#dropdown-third-replace", drupal_render($form['foss_sub_project_status'])); + } else { + $form['dropdown-third-replace']['#markup'] = ""; + $commands[] = ajax_command_html("#dropdown-third-replace", ""); + } + return array( + '#type' => 'ajax', + '#commands' => $commands + ); +} + +//this is ajax callback method for second dropdown ie Activities type +function ajax_foss_sub_project_dependent_dropdown_callback($form, &$form_state) +{ + $foss_project = $form_state['values']['foss_sub_project']; + + $foss_type = $form_state['values']['foss_type']; + if ($foss_type != "" && $foss_project != 0 && $foss_type != 3) { + + if($foss_project==7){ + $form['load_city']['#markup'] = ""; + $commands[] = ajax_command_html("#load_city", ""); + $form['load_country']['#markup'] = ""; + $commands[] = ajax_command_html("#load_country", ""); + $form['load_state']['#markup'] = ""; + $commands[] = ajax_command_html("#load_state", ""); + + }else if($foss_project==6){ + $form['load_city']['#markup'] = ""; + $commands[] = ajax_command_html("#load_city", ""); + $form['load_country']['#markup'] = ""; + $commands[] = ajax_command_html("#load_country", ""); + $form['load_state']['#markup'] = ""; + $commands[] = ajax_command_html("#load_state", ""); + $form['end_date']['#markup'] = ""; + $commands[] = ajax_command_html("#enddate", ""); + $form['start_date']['#markup'] = ""; + $commands[] = ajax_command_html("#startdate", ""); + + }else{ + + $form['countryname']['#type'] = "select"; + $form['countryname']['#title'] = t("Select Country"); + $form['countryname']['#option'] = get_country_list($foss_type, $foss_project); + $form['countryname']['#prefix'] = "
"; + $form['countryname']['#suffix'] = "
"; + $commands[] = ajax_command_html("#load_country", drupal_render($form['countryname'])); + $country_value = $form_state['values']['countryname']; + + $form['statename']['#type'] = "select"; + $form['statename']['#title'] = t("State Name"); + $form['statename']['#options'] = get_state_list($foss_type, $foss_project, $country_value); + $form['statename']['#prefix'] = "
"; + $form['statename']['#suffix'] = "
"; + $commands[] = ajax_command_html("#load_state", drupal_render($form['statename'])); + $state_value = $form_state['values']['statename']; + + $form['cityname']['#type'] = "select"; + $form['cityname']['#title'] = t("City Name"); + $form['cityname']['#options'] = get_city_list($foss_type, $foss_project, $country_value, $state_value); + $form['cityname']['#prefix'] = "
"; + $form['cityname']['#suffix'] = "
"; + $commands[] = ajax_command_html("#load_city", drupal_render($form['cityname'])); + + } + + } else { + if ($foss_project == 3 || $foss_project == 4 || $foss_project == 5) { + + $form['start_date']['#type'] = "date_popup"; + $form['start_date']['#title'] = t('From Date:'); + $form['start_date']['#date_label_position'] = ''; + $form['start_date']['#description'] = ''; + $form['start_date']['#default_value'] = ''; + $form['start_date']['#date_format'] = 'Y-m-d'; + $form['start_date']['#date_increment'] = 0; + $form['start_date']['#date_year_range'] = '2011:+0'; + $form['start_date']['#datepicker_options'] = array( + 'maxDate' => 0 + ); + $commands[] = ajax_command_html("#startdate", drupal_render($form['start_date'])); + $form['end_date']['#type'] = "date_popup"; + $form['end_date']['#title'] = t('To Date:'); + $form['end_date']['#date_label_position'] = ''; + $form['end_date']['#description'] = ''; + $form['end_date']['#default_value'] = ''; + $form['end_date']['#date_format'] = 'Y-m-d'; + $form['end_date']['#date_increment'] = 0; + $form['end_date']['#date_year_range'] = '2011:+0'; + $form['end_date']['#datepicker_options'] = array( + 'maxDate' => 0 + ); + $commands[] = ajax_command_html("#enddate", drupal_render($form['end_date'])); + + $form['countryname']['#type'] = "select"; + $form['countryname']['#title'] = t("Select Country"); + $form['countryname']['#option'] = get_country_list($foss_type, $foss_project); + $form['countryname']['#prefix'] = "
"; + $form['countryname']['#suffix'] = "
"; + $commands[] = ajax_command_html("#load_country", drupal_render($form['countryname'])); + + $country_value = $form_state['values']['countryname']; + + $form['statename']['#type'] = "select"; + $form['statename']['#title'] = t("State Name"); + $form['statename']['#options'] = get_state_list($foss_type, $foss_project, $country_value); + $form['statename']['#prefix'] = "
"; + $form['statename']['#suffix'] = "
"; + $commands[] = ajax_command_html("#load_state", drupal_render($form['statename'])); + $state_value = $form_state['values']['statename']; + + $form['cityname']['#type'] = "select"; + $form['cityname']['#title'] = t("City Name"); + $form['cityname']['#options'] = get_city_list($foss_type, $foss_project, $country_value, $state_value); + $form['cityname']['#prefix'] = "
"; + $form['cityname']['#suffix'] = "
"; + $commands[] = ajax_command_html("#load_city", drupal_render($form['cityname'])); + + + }else if($foss_project == 7){ + $form['start_date']['#type'] = "date_popup"; + $form['start_date']['#title'] = t('From Date:'); + $form['start_date']['#date_label_position'] = ''; + $form['start_date']['#description'] = ''; + $form['start_date']['#default_value'] = ''; + $form['start_date']['#date_format'] = 'Y-m-d'; + $form['start_date']['#date_increment'] = 0; + $form['start_date']['#date_year_range'] = '2011:+0'; + $form['start_date']['#datepicker_options'] = array( + 'maxDate' => 0 + ); + $commands[] = ajax_command_html("#startdate", drupal_render($form['start_date'])); + $form['end_date']['#type'] = "date_popup"; + $form['end_date']['#title'] = t('To Date:'); + $form['end_date']['#date_label_position'] = ''; + $form['end_date']['#description'] = ''; + $form['end_date']['#default_value'] = ''; + $form['end_date']['#date_format'] = 'Y-m-d'; + $form['end_date']['#date_increment'] = 0; + $form['end_date']['#date_year_range'] = '2011:+0'; + $form['end_date']['#datepicker_options'] = array( + 'maxDate' => 0 + ); + $commands[] = ajax_command_html("#enddate", drupal_render($form['end_date'])); + $form['load_city']['#markup'] = ""; + $commands[] = ajax_command_html("#load_city", ""); + $form['load_country']['#markup'] = ""; + $commands[] = ajax_command_html("#load_country", ""); + $form['load_state']['#markup'] = ""; + $commands[] = ajax_command_html("#load_state", ""); + }else if($foss_project == 6){ + $form['load_city']['#markup'] = ""; + $commands[] = ajax_command_html("#load_city", ""); + $form['load_country']['#markup'] = ""; + $commands[] = ajax_command_html("#load_country", ""); + $form['load_state']['#markup'] = ""; + $commands[] = ajax_command_html("#load_state", ""); + $form['end_date']['#markup'] = ""; + $commands[] = ajax_command_html("#enddate", ""); + $form['start_date']['#markup'] = ""; + $commands[] = ajax_command_html("#startdate", ""); + } + } + if ($foss_project == 1 || $foss_project == 2) { + $form['foss_sub_project_status']['#type'] = "select"; + $form['foss_sub_project_status']['#title'] = t("Status"); + $form['foss_sub_project_status']['#options'] = _ajax_example_get_third_dropdown_options($foss_project); + $commands[] = ajax_command_html("#dropdown-third-replace", drupal_render($form['foss_sub_project_status'])); + } else { + $form['dropdown-third-replace']['#markup'] = ""; + $commands[] = ajax_command_html("#dropdown-third-replace", ""); + + } + return array( + '#type' => 'ajax', + '#commands' => $commands + ); +} + +//Form Submit +function ajax_example_submit_driven_callback($form, &$form_state) +{ + $foss_type = $form['foss_type']['#options'][$form_state['values']['foss_type']]; + $foss_sub_project = $form['foss_sub_project']['#options'][$form_state['values']['foss_sub_project']]; + $foss_sub_project_status = $form['foss_sub_project_status']['#options'][$form_state['values']['foss_sub_project_status']]; + $startdate = $form_state['values']['start_date']; + $startdate = trim($startdate); + $enddate = $form_state['values']['end_date']; + $enddate = trim($enddate); + $countryname = $form['countryname']['#options'][$form_state['values']['countryname']]; + $countryname = trim($countryname); + $cityname = $form['cityname']['#options'][$form_state['values']['cityname']]; + $cityname = trim($cityname); + $statename = $form['statename']['#options'][$form_state['values']['statename']]; + $statename = trim($statename); + $link_flag = 0; + + if ($cityname == "--------------" || $cityname == "") { + $cityname = "%"; + } else { + $cityname = $cityname; + } + if ($statename == "--------------" || $statename == "") { + $statename = "%"; + } else { + $statename = $statename; + } + if ($countryname == "--------------" || $countryname == "") { + $countryname = "%"; + } else { + $countryname = $countryname; + } + if ($startdate == "") { + $startdate = '1960-01-01'; + } else { + $startdate = $startdate; + } + if ($enddate == "") { + $enddate = date("Y-m-d"); + } else { + $enddate = $enddate; + } + if ($foss_type == '--------------') { + $form['default_load']['#markup'] = ' +
+ +
' . get_tabledata_TBC_or_LM("TBC", $startdate, $enddate) .' +
' . drupal_render(getchart("TBC")) . '
+
+ +
' . get_tabledata_TBC_or_LM("LM", $startdate, $enddate) .' +
' . drupal_render(getchart("LM")) . '
+
+ +
' . workshop_view_all(0, $startdate, $enddate) .'
+ +
' . getselfworkshoplcount(0,$startdate,$enddate,"","").'
+ +
' . conference_seminar_view_all(0, "", "") .'
+ +
'.spokentutorial_view_all("").'
+
+ '; + $commands[] = ajax_command_html("#default_load", drupal_render($form['default_load'])); + } else if ($foss_type != '--------------' && (($foss_sub_project == "--------------") || ($foss_sub_project == "No Sub-Project Available"))) { + $form['displaytext']['#markup'] = "Statistic of project : " . $foss_type; + $commands[] = ajax_command_html("#displaytext", drupal_render($form['displaytext'])); + db_set_active('default'); // We need to call the main (drupal) db back + db_set_active(); // without the paramater means set back to the default for the site + $query = db_select('foss_type'); + $query->fields('foss_type', array( + 'tbc', + 'lab_migration', + 'workshop', + 'self_workshop', + 'conference' + )); + $query->fields('foss_type', array( + 'spoken_tutorial', + 'postal_campaigns' + )); + $query->condition('foss_name', $foss_type); + $result = $query->execute(); + $subproject_detail = $result->fetchObject(); + $optiondata = array( + "tbc", + "lab_migration", + "workshop", + "self_workshop", + "conference", + "spoken_tutorial", + "postal_campaigns" + ); + $optionvalue = array( + " ", + "Textbook Companion", + "Lab Migration", + "Workshop", + "Self Workshop", + "Conference", + "Spoken Tutorial", + "Postal Campaigns" + ); + $i = 0; + $pagecontent = ""; + // foreach ($optiondata as $value) { + // $i++; + // //$options[$i]=$optionvalue[$i]; + // if (($subproject_detail->$value) != 0) { + // if ($value == "tbc") { + // $pagecontent .= "
+ // + // + //
" . get_tabledata_selectedFoss_TBC_LM($foss_type, 'TBC', 'all', $startdate, $enddate, $countryname, $statename, $cityname, $link_flag) . "
" . drupal_render(getchartforselectedProject($foss_type, "TBC", $startdate, $enddate, $countryname, $statename, $cityname)) . "
"; + // } else if ($value == "lab_migration") { + // $pagecontent .= "
+ // + // + //
+ //
" . get_tabledata_selectedFoss_TBC_LM($foss_type, 'LM', "all", $startdate, $enddate, $countryname, $statename, $cityname, $link_flag) . "
+ //
" . drupal_render(getchartforselectedProject($foss_type, "LM", $startdate, $enddate, $countryname, $statename, $cityname)) . "
"; + // } else if ($value == "workshop") { + + // $event_type = "Workshop"; + // $pagecontent .= "
+ // + // + //
" . events_view_filter($foss_type, $event_type, $startdate, $enddate, $countryname, $statename, $cityname) . "
"; + // } else if ($value == "self_workshop") { + // $pagecontent .= "
+ // + // + //
".getselfworkshoplcount($foss_type,$startdate,$enddate, $statename, $cityname)."
"; + // } else if ($value == "conference") { + // $event_type = "Conference"; + // $pagecontent .= "
+ // + // + //
" . events_view_filter($foss_type, $event_type, $startdate, $enddate, $countryname, $statename, $cityname) . "
"; + // } else if ($value == "spoken_tutorial") { + // $pagecontent .= "
+ // + // + //
".spokentutorial_view_all($foss_type)."
"; + // } + + + // } else { + // if ($value == "tbc") { + // $pagecontent .= "
+ // + // + //
" . t(" + //
TextBook Companion Project Not Present
") . "
"; + // } else if ($value == "lab_migration") { + // $pagecontent .= "
+ // + // + //
+ //
" . t(" + //
Lab Migration Project Not Present
") . "
"; + // } else if ($value == "workshop") { + // $pagecontent .= "
+ // + // + //
" . t(" + //
No Workshop were conducted
") . "
"; + // } else if ($value == "self_workshop") { + // $pagecontent .= "
+ // + // + //
" . t(" + //
No Self Workshop were conducted
") . "
"; + // } else if ($value == "conference") { + // $pagecontent .= "
+ // + // + //
" . t(" + //
No Conference were conducted
") . "
"; + // } else if ($value == "spoken_tutorial") { + // $pagecontent .= "
+ // + // + //
" . t(" + //
Spoken Tutorial Not Present
") . "
"; + // } + // } + // } + // $form['default_load']['#markup'] = $pagecontent; + $form['default_load']['#markup'] = ' +
+ +
' . get_tabledata_selectedFoss_TBC_LM($foss_type, 'TBC', 'all', $startdate, $enddate, $countryname, $statename, $cityname, $link_flag) .' +
' . drupal_render(getchartforselectedProject($foss_type, "TBC", $startdate, $enddate, $countryname, $statename, $cityname)) . '
+
+
' . get_tabledata_selectedFoss_TBC_LM($foss_type, 'LM', "all", $startdate, $enddate, $countryname, $statename, $cityname, $link_flag) . ' +
' . drupal_render(getchartforselectedProject($foss_type, "LM", $startdate, $enddate, $countryname, $statename, $cityname)) . '
+
+
+ '. events_view_filter($foss_type, "Workshop", $startdate, $enddate, $countryname, $statename, $cityname) . '
+
' . getselfworkshoplcount($foss_type,$startdate,$enddate, $statename, $cityname).'
+
' . events_view_filter($foss_type,"Conference", $startdate, $enddate, $countryname, $statename, $cityname) .'
+ +
' .spokentutorial_view_all($foss_type).'
+
+ '; + + $commands[] = ajax_command_html("#default_load", drupal_render($form['default_load'])); + + } else if ($foss_type != '--------------' && $foss_sub_project == "Textbook Companion" && $foss_sub_project_status == "--------------") { + + $form['displaytext']['#markup'] = "Statistic of project : " . $foss_type; + $commands[] = ajax_command_html("#displaytext", drupal_render($form['displaytext'])); + $pagecontent = ""; + $pagecontent .= ' +
+ +
' . get_tabledata_selectedFoss_TBC_LM($foss_type, 'TBC', 'all', $startdate, $enddate, $countryname, $statename, $cityname, $link_flag) . ' +
' . drupal_render(getchartforselectedProject($foss_type, "TBC", $startdate, $enddate, $countryname, $statename, $cityname)) . '
+
'; + $form['default_load']['#markup'] = $pagecontent; + $commands[] = ajax_command_html("#default_load", drupal_render($form['default_load'])); + + } else if ($foss_type != '--------------' && $foss_sub_project == "Lab Migration" && $foss_sub_project_status == "--------------") { + $form['displaytext']['#markup'] = "Statistic of project : " . $foss_type; + $commands[] = ajax_command_html("#displaytext", drupal_render($form['displaytext'])); + $pagecontent = ""; + $pagecontent .= ' +
+ +
' . get_tabledata_selectedFoss_TBC_LM($foss_type, 'LM', "all", $startdate, $enddate, $countryname, $statename, $cityname, $link_flag) . ' +
' . drupal_render(getchartforselectedProject($foss_type, "LM", $startdate, $enddate, $countryname, $statename, $cityname)) . '
+
'; + $form['default_load']['#markup'] = $pagecontent; + $commands[] = ajax_command_html("#default_load", drupal_render($form['default_load'])); + + } else if ($foss_type != '--------------' && $foss_sub_project == "Workshop") { + + $form['displaytext']['#markup'] = "Statistic of project : " . $foss_type; + $commands[] = ajax_command_html("#displaytext", drupal_render($form['displaytext'])); + + + $pagecontent = ""; + $pagecontent .= ' +
+ +
' .events_view_filter($foss_type, $foss_sub_project, $startdate, $enddate, $countryname, $statename, $cityname) .'
'; + + $form['default_load']['#markup'] = $pagecontent; + $commands[] = ajax_command_html("#default_load", drupal_render($form['default_load'])); + + } else if ($foss_type != '--------------' && $foss_sub_project == "Self Workshop") { + + $form['displaytext']['#markup'] = "Statistic of project : " . $foss_type; + $commands[] = ajax_command_html("#displaytext", drupal_render($form['displaytext'])); + + $pagecontent = ""; + $pagecontent .= ' +
+ +
' . getselfworkshoplcount($foss_type,$startdate,$enddate, $statename, $cityname).'
'; + + $form['default_load']['#markup'] = $pagecontent; + $commands[] = ajax_command_html("#default_load", drupal_render($form['default_load'])); + + }else if ($foss_type != '--------------' && $foss_sub_project == "Conference") { + + $form['displaytext']['#markup'] = "Statistic of project : " . $foss_type; + $commands[] = ajax_command_html("#displaytext", drupal_render($form['displaytext'])); + + + $pagecontent = ""; + $pagecontent .= ' +
+ +
' . events_view_filter($foss_type, $foss_sub_project, $startdate, $enddate, $countryname, $statename, $cityname).'
'; + + $form['default_load']['#markup'] = $pagecontent; + $commands[] = ajax_command_html("#default_load", drupal_render($form['default_load'])); + + }else if ($foss_type != '--------------' && $foss_sub_project == "Spoken Tutorial") { + + $form['displaytext']['#markup'] = "Statistic of project : " . $foss_type; + $commands[] = ajax_command_html("#displaytext", drupal_render($form['displaytext'])); + + + $pagecontent = ""; + $pagecontent .= ' +
+ +
'.spokentutorial_view_all($foss_type) .'
'; + + $form['default_load']['#markup'] = $pagecontent; + $commands[] = ajax_command_html("#default_load", drupal_render($form['default_load'])); +} + +/* else if ($foss_type != '--------------' && $foss_sub_project == "Postal Campaigns") { + + $form['displaytext']['#markup'] = "Statistic of project : " . $foss_type; + $commands[] = ajax_command_html("#displaytext", drupal_render($form['displaytext'])); + + + $pagecontent = ""; + $pagecontent .= "
+ + +
" . postalcampaign_view_all($foss_type, $startdate, $enddate) . "
"; + + $form['default_load']['#markup'] = $pagecontent; + $commands[] = ajax_command_html("#default_load", drupal_render($form['default_load'])); + + }*/ + + else if ($foss_type != '--------------' && ($foss_sub_project == "Textbook Companion" || $foss_sub_project == "Lab Migration") && $foss_sub_project_status != "--------------") { + if ($foss_sub_project == "Textbook Companion" && $foss_sub_project_status == "Completed Books") { + $title = "Textbook Companion"; + $datatable = get_tabledata_selectedFoss_TBC_LM($foss_type, 'TBC', "completed", $startdate, $enddate, $countryname, $statename, $cityname, $link_flag); + } else if ($foss_sub_project == "Lab Migration" && $foss_sub_project_status == "Completed Labs") { + $title = "Lab Migration"; + $datatable = get_tabledata_selectedFoss_TBC_LM($foss_type, 'LM', "completed", $startdate, $enddate, $countryname, $statename, $cityname, $link_flag); + } else if ($foss_sub_project == "Textbook Companion" && $foss_sub_project_status == "Books in Progress") { + $title = "Textbook Companion"; + $datatable = get_tabledata_selectedFoss_TBC_LM($foss_type, 'TBC', "pending", $startdate, $enddate, $countryname, $statename, $cityname, $link_flag); + } else if ($foss_sub_project == "Lab Migration" && $foss_sub_project_status == "Labs in Progress") { + $title = "Lab Migration"; + $datatable = get_tabledata_selectedFoss_TBC_LM($foss_type, 'LM', "pending", $startdate, $enddate, $countryname, $statename, $cityname, $link_flag); + } + $form['displaytext']['#markup'] = "Statistic of project : " . $foss_type; + $commands[] = ajax_command_html("#displaytext", drupal_render($form['displaytext'])); + $form['default_load']['#markup'] = ' +
+
'. $datatable . '
+
'; + $commands[] = ajax_command_html("#default_load", drupal_render($form['default_load'])); + + } + + return array( + '#type' => 'ajax', + '#commands' => $commands + ); +} + +//General Function to create table +function bootstrap_table_format($headers, $rows) +{ + $thead = ""; + $tbody = ""; + foreach ($headers as $header) { + $thead .= "{$header}"; + } + foreach ($rows as $row) { + $tbody .= ""; + $i = 0; + foreach ($row as $data) { + $datalable = $headers[$i++]; + $tbody .= "{$data}"; + } + $tbody .= ""; + } + $table = " + + + {$thead} + {$tbody} +
+ + "; + return $table; +} + +//Returns table with count of TBC /LM +function get_tabledata_TBC_or_LM($sub_type, $startdate, $enddate) +{ + if ($enddate == "") { + $enddate = date("Y-m-d"); + } + $rows = array(); + $headers = array( + " Project", + "Completed", + "In Progress" + ); + if ($sub_type == 'TBC') { + $query = db_select('foss_type'); + $query->fields('foss_type', array( + 'id' + )); + $query->fields('foss_type', array( + 'foss_name' + )); + $query->fields('foss_type', array( + 'tbc' + )); + $query->fields('foss_type', array( + 'tbc_completed' + )); + $query->fields('foss_type', array( + 'tbc_pending' + )); + $query->condition('tbc', 1); + $result = $query->execute(); + while ($foss_detail = $result->fetchObject()) { + $foss_type = $foss_detail->foss_name; + db_set_active($foss_type); + if ($foss_detail->foss_name != 'Python') { + db_set_active($foss_detail->foss_name); //Active other database + if ($foss_detail->foss_name != 'eSim' && $foss_detail->foss_name != 'OpenFOAM' && $foss_detail->foss_name != 'OR-Tools') { + if ($foss_detail->foss_name != 'DWSIM') { + $query2 = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND pe.category>0 AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate ", array( + ':startdate' => $startdate, + ':enddate' => $enddate + )); + } else { + $query2 = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND pe.category>0 AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate ", array( + ':startdate' => $startdate, + ':enddate' => $enddate + )); + } + } else { + $query2 = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate ", array( + ':startdate' => $startdate, + ':enddate' => $enddate + )); + } + $completedbookcount = $query2->fetchObject()->book_count; + if ($foss_detail->tbc_completed != "" && $foss_detail->tbc_completed != null) { + $clink = "" . $completedbookcount . ""; + $completedbookcount = $clink; + } + + /* For setting completion date for pending TBC and LM more */ + $pending_enddate = date('Y-m-d', strtotime("+5 months", strtotime( $enddate))); + + if ($foss_detail->foss_name != 'eSim' && $foss_detail->foss_name != 'OpenFOAM' && $foss_detail->foss_name != 'OR-Tools') { + if ($foss_detail->foss_name != 'DWSIM') { + $query3 = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status !=3 AND pe.approval_status =1 AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate ", array( + ':startdate' => $startdate, + ':enddate' => $pending_enddate + )); + } else { + $query3 = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status !=3 AND pe.approval_status =1 AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate ", array( + ':startdate' => $startdate, + ':enddate' => $pending_enddate + )); + } + } else { + $query3 = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status !=3 AND pe.approval_status =1 AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate ", array( + ':startdate' => $startdate, + ':enddate' => $pending_enddate + )); + } + $pendingbookcount = $query3->fetchObject()->book_count; + if ($foss_detail->tbc_pending != "" && $foss_detail->tbc_pending != null) { + $plink = "" . $pendingbookcount . ""; + $pendingbookcount = $plink; + } + db_set_active('default'); // We need to call the main (drupal) db back + db_set_active(); // without the paramater means set back to the default for the site + $item = array( + $foss_detail->foss_name, + $completedbookcount, + $pendingbookcount + ); + array_push($rows, $item); + } else { + //For Python TBC + db_set_active($foss_detail->foss_name); //Active other database + $query5 = db_select('tbc_book'); + $query5->addExpression('count(*)', 'count'); + $query5->condition('approved', 1); + $result5 = $query5->execute(); + $completedbookcount = $result5->fetchObject()->count; + if ($foss_detail->tbc_completed != "" && $foss_detail->tbc_completed != null) { + $clink = "" . $completedbookcount . ""; + $completedbookcount = $clink; + } + $query6 = db_select('tbc_book'); + $query6->addExpression('count(*)', 'count'); + $query6->condition('approved', 1, '<>'); + $result6 = $query6->execute(); + $pendingbookcount = $result6->fetchObject()->count; + if ($foss_detail->tbc_pending != "" && $foss_detail->tbc_pending != null) { + $plink = "" . $pendingbookcount . ""; + $pendingbookcount = $plink; + } + db_set_active('default'); // We need to call the main (drupal) db back + db_set_active(); // without the paramater means set back to the default for the site + $item = array( + $foss_detail->foss_name, + $completedbookcount, + $pendingbookcount + ); + array_push($rows, $item); + } + } + } else { + $query = db_select('foss_type'); + $query->fields('foss_type', array( + 'id' + )); + $query->fields('foss_type', array( + 'foss_name' + )); + $query->fields('foss_type', array( + 'lab_migration' + )); + $query->fields('foss_type', array( + 'lm_completed' + )); + $query->fields('foss_type', array( + 'lm_pending' + )); + $query->condition('lab_migration', 1); + $result = $query->execute(); + while ($foss_detail = $result->fetchObject()) { + db_set_active($foss_detail->foss_name); //Active other database + $query2 = db_select('lab_migration_proposal'); + $query2->addExpression('count(*)', 'count'); + $query2->condition('approval_status', 3); + $result2 = $query2->execute(); + $completedlabcount = $result2->fetchObject()->count; + if ($foss_detail->lm_completed != "" && $foss_detail->lm_completed != null) { + $clink = "" . $completedlabcount . ""; + $completedlabcount = $clink; + } + $query3 = db_select('lab_migration_proposal'); + $query3->addExpression('count(*)', 'count'); + $query3->condition('approval_status', 1); + $result3 = $query3->execute(); + $pendinglabcount = $result3->fetchObject()->count; + if ($foss_detail->lm_pending != "" && $foss_detail->lm_pending != null) { + $plink = "" . $pendinglabcount . ""; + $pendinglabcount = $plink; + } + $item = array( + $foss_detail->foss_name, + $completedlabcount, + $pendinglabcount + ); + array_push($rows, $item); + } + } + db_set_active('default'); // We need to call the main (drupal) db back + db_set_active(); // without the paramater means set back to the default for the site + $count = bootstrap_table_format($headers, $rows); + return $count; +} + +// This is used to return tables with count of TBC and LM but after applying all filters + +function get_tabledata_selectedFoss_TBC_LM($foss_type, $sub_type, $status, $startdate, $enddate, $countryname, $statename, $cityname, $link_flag) +{ + + //This is for sending values through URL as '%' is not allow through url + + if ($cityname == "%") { + $city = "null"; + } else { + $city = $cityname; + } + if ($statename == "%") { + $state = "null"; + } else { + $state = $statename; + } + if ($countryname == "%") { + $country = "null"; + } else { + $country = $countryname; + } + + if ($status == "all") { + $rows = array(); + if ($sub_type == 'TBC') { + $headers = array( + "Completed Book", + "Book In Progress" + ); + $query = db_select('foss_type'); + $query->fields('foss_type', array( + 'id' + )); + $query->fields('foss_type', array( + 'foss_name' + )); + $query->fields('foss_type', array( + 'tbc' + )); + $query->fields('foss_type', array( + 'tbc_completed' + )); + $query->fields('foss_type', array( + 'tbc_pending' + )); + $query->condition('foss_name', $foss_type); + $query->condition('tbc', 1); + $result = $query->execute(); + $foss_detail = $result->fetchObject(); + $foss_type = $foss_detail->foss_name; + db_set_active($foss_type); + if ($foss_detail->foss_name != 'Python') { + db_set_active($foss_detail->foss_name); //Active other database + if ($foss_detail->foss_name != 'eSim' && $foss_detail->foss_name != 'OpenFOAM' && $foss_detail->foss_name != 'OR-Tools') { + if ($foss_detail->foss_name != 'DWSIM') { + $query2 = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND pe.category>0 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + } else { + $query2 = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND pe.category>0 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + } + } else { + $query2 = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + } + $completedbookcount = $query2->fetchObject()->book_count; + if ($foss_detail->tbc_completed != "" && $foss_detail->tbc_completed != null && $link_flag != 1) { + + //$clink = "" . $completedbookcount . ""; + if ($completedbookcount != 0 || $completedbookcount != "0") { + $clink = "" . $completedbookcount . ""; + $completedbookcount = $clink; + } else { + $completedbookcount = $completedbookcount; + } + + } + if ($foss_detail->foss_name != 'eSim' && $foss_detail->foss_name != 'OpenFOAM' && $foss_detail->foss_name != 'OR-Tools') { + if ($foss_detail->foss_name != 'DWSIM') { + $query3 = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status !=3 AND pe.approval_status =1 AND pe.category>0 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate ", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + } else { + $query3 = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status !=3 AND pe.approval_status =1 AND pe.category>0 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + } + } else { + $query3 = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status !=3 AND pe.approval_status =1 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + } + $pendingbookcount = $query3->fetchObject()->book_count; + if ($foss_detail->tbc_pending != "" && $foss_detail->tbc_pending != null && $link_flag != 1) { + //$plink = "" . $pendingbookcount . ""; + if ($pendingbookcount != 0 || $pendingbookcount != "0") { + $plink = "" . $pendingbookcount . ""; + $pendingbookcount = $plink; + } else { + $pendingbookcount = $pendingbookcount; + } + + } + //db_set_active('default'); // We need to call the main (drupal) db back + //db_set_active(); // without the paramater means set back to the default for the site + $item = array( + $completedbookcount, + $pendingbookcount + ); + array_push($rows, $item); + } else { + //For Python TBC + db_set_active($foss_detail->foss_name); //Active other database + $query5 = db_select('tbc_book'); + $query5->addExpression('count(*)', 'count'); + $query5->condition('approved', 1); + //$query5->condition('author', '%'.$extrafilter.'%', 'LIKE'); + $result5 = $query5->execute(); + $completedbookcount = $result5->fetchObject()->count; + if ($foss_detail->tbc_completed != "" && $foss_detail->tbc_completed != null && $link_flag != 1) { + $clink = "" . $completedbookcount . ""; + $completedbookcount = $clink; + } + $query6 = db_select('tbc_book'); + $query6->addExpression('count(*)', 'count'); + $query6->condition('approved', 1, '<>'); + //$query6->condition('author', '%'.$extrafilter.'%', 'LIKE'); + $result6 = $query6->execute(); + $pendingbookcount = $result6->fetchObject()->count; + if ($foss_detail->tbc_pending != "" && $foss_detail->tbc_pending != null && $link_flag != 1) { + $plink = "" . $pendingbookcount . ""; + $pendingbookcount = $plink; + } + //db_set_active('default'); // We need to call the main (drupal) db back + //db_set_active(); // without the paramater means set back to the default for the site + $item = array( + $completedbookcount, + $pendingbookcount + ); + array_push($rows, $item); + } + } else { + $headers = array( + "Completed Labs", + "Labs In Progress" + ); + $query = db_select('foss_type'); + $query->fields('foss_type', array( + 'id' + )); + $query->fields('foss_type', array( + 'foss_name' + )); + $query->fields('foss_type', array( + 'lab_migration' + )); + $query->fields('foss_type', array( + 'lm_completed' + )); + $query->fields('foss_type', array( + 'lm_pending' + )); + $query->condition('foss_name', $foss_type); + $query->condition('lab_migration', 1); + $result = $query->execute(); + $foss_detail = $result->fetchObject(); + db_set_active($foss_detail->foss_name); //Active other database + $query2 = db_query("SELECT COUNT(*) AS count from lab_migration_proposal WHERE approval_status=3 AND city LIKE :city AND state LIKE :state AND country LIKE :country AND FROM_UNIXTIME(approval_date) >=:startdate AND FROM_UNIXTIME(approval_date) <=:enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + $completedlabcount = $query2->fetchObject()->count; + if ($foss_detail->lm_completed != "" && $foss_detail->lm_completed != null && $link_flag != 1) { + //$clink = "" . $completedlabcount . ""; + if ($completedlabcount != 0 || $completedlabcount != "0") { + $clink = "" . $completedlabcount . ""; + $completedlabcount = $clink; + } else { + $completedlabcount = $completedlabcount; + } + } + $query3 = db_query("SELECT COUNT(*) AS count from lab_migration_proposal WHERE approval_status=1 AND city LIKE :city AND state LIKE :state AND country LIKE :country AND FROM_UNIXTIME(approval_date) >=:startdate AND FROM_UNIXTIME(approval_date) <=:enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + $pendinglabcount = $query3->fetchObject()->count; + if ($foss_detail->lm_pending != "" && $foss_detail->lm_pending != null && $link_flag != 1) { + //$plink = "" . $pendinglabcount . ""; + if ($pendinglabcount != 0 || $pendinglabcount != "0") { + $plink = "" . $pendinglabcount . ""; + $pendinglabcount = $plink; + } else { + $pendinglabcount = $pendinglabcount; + } + } + $item = array( + $completedlabcount, + $pendinglabcount + ); + array_push($rows, $item); + } + db_set_active('default'); // We need to call the main (drupal) db back + db_set_active(); // without the paramater means set back to the default for the site + $count = bootstrap_table_format($headers, $rows); + return $count; + } else if ($status == "completed") { + $rows = array(); + if ($sub_type == 'TBC') { + $headers = array( + "Completed Book" + ); + $query = db_select('foss_type'); + $query->fields('foss_type', array( + 'id' + )); + $query->fields('foss_type', array( + 'foss_name' + )); + $query->fields('foss_type', array( + 'tbc' + )); + $query->fields('foss_type', array( + 'tbc_completed' + )); + $query->condition('foss_name', $foss_type); + $query->condition('tbc', 1); + $result = $query->execute(); + $foss_detail = $result->fetchObject(); + $foss_type = $foss_detail->foss_name; + db_set_active($foss_type); + if ($foss_detail->foss_name != 'Python') { + db_set_active($foss_detail->foss_name); //Active other database + if ($foss_detail->foss_name != 'eSim' && $foss_detail->foss_name != 'OpenFOAM' && $foss_detail->foss_name != 'OR-Tools') { + if ($foss_detail->foss_name != 'DWSIM') { + $query2 = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND pe.category>0 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + } else { + $query2 = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND pe.category>0 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate ", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + } + } else { + $query2 = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + } + $completedbookcount = $query2->fetchObject()->book_count; + if ($foss_detail->tbc_completed != "" && $foss_detail->tbc_completed != null && $link_flag != 1) { + //$clink = "" . $completedbookcount . ""; + if ($completedbookcount != 0 || $completedbookcount != "0") { + $clink = "" . $completedbookcount . ""; + $completedbookcount = $clink; + } else { + $completedbookcount = $completedbookcount; + } + + } + $item = array( + $completedbookcount + ); + array_push($rows, $item); + } else { + //For Python TBC + db_set_active($foss_detail->foss_name); //Active other database + $query5 = db_select('tbc_book'); + $query5->addExpression('count(*)', 'count'); + $query5->condition('approved', 1); + //$query5->condition('author', '%'.$extrafilter.'%', 'LIKE'); + $result5 = $query5->execute(); + $completedbookcount = $result5->fetchObject()->count; + if ($foss_detail->tbc_completed != "" && $foss_detail->tbc_completed != null && $link_flag != 1) { + $clink = "" . $completedbookcount . ""; + $completedbookcount = $clink; + } + $item = array( + $completedbookcount + ); + array_push($rows, $item); + } + } else { + $headers = array( + "Completed Labs" + ); + $query = db_select('foss_type'); + $query->fields('foss_type', array( + 'id' + )); + $query->fields('foss_type', array( + 'foss_name' + )); + $query->fields('foss_type', array( + 'lab_migration' + )); + $query->fields('foss_type', array( + 'lm_completed' + )); + $query->condition('foss_name', $foss_type); + $query->condition('lab_migration', 1); + $result = $query->execute(); + $foss_detail = $result->fetchObject(); + db_set_active($foss_detail->foss_name); //Active other database + $query2 = db_query("SELECT COUNT(*) AS count from lab_migration_proposal WHERE approval_status=3 AND city LIKE :city AND state LIKE :state AND country LIKE :country AND FROM_UNIXTIME(approval_date) >=:startdate AND FROM_UNIXTIME(approval_date) <=:enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + $completedlabcount = $query2->fetchObject()->count; + if ($foss_detail->lm_completed != "" && $foss_detail->lm_completed != null && $link_flag != 1) { + //$clink = "" . $completedlabcount . ""; + if ($completedlabcount != "0" || $completedlabcount != 0) { + $clink = "" . $completedlabcount . ""; + $completedlabcount = $clink; + } else { + $completedlabcount = $completedlabcount; + } + + } + $item = array( + $completedlabcount + ); + array_push($rows, $item); + } + db_set_active('default'); // We need to call the main (drupal) db back + db_set_active(); // without the paramater means set back to the default for the site + $count = bootstrap_table_format($headers, $rows); + } else if ($status == "pending") { + $rows = array(); + if ($sub_type == 'TBC') { + $headers = array( + "Books in Progress" + ); + $query = db_select('foss_type'); + $query->fields('foss_type', array( + 'id' + )); + $query->fields('foss_type', array( + 'foss_name' + )); + $query->fields('foss_type', array( + 'tbc' + )); + $query->fields('foss_type', array( + 'tbc_pending' + )); + $query->condition('foss_name', $foss_type); + $query->condition('tbc', 1); + $result = $query->execute(); + $foss_detail = $result->fetchObject(); + $foss_type = $foss_detail->foss_name; + db_set_active($foss_type); + if ($foss_detail->foss_name != 'Python') { + db_set_active($foss_detail->foss_name); //Active other database + if ($foss_detail->foss_name != 'eSim' && $foss_detail->foss_name != 'OpenFOAM' && $foss_detail->foss_name != 'OR-Tools') { + if ($foss_detail->foss_name != 'DWSIM') { + $query2 = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status !=3 AND pe.approval_status =1 AND pe.category>0 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + } else { + $query2 = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status !=3 AND pe.approval_status =1 AND pe.category>0 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate ", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + } + } else { + $query2 = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status !=3 AND pe.approval_status =1 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + } + $pendingbookcount = $query2->fetchObject()->book_count; + if ($foss_detail->tbc_pending != "" && $foss_detail->tbc_pending != null && $link_flag != 1) { + //$plink = "" . $pendingbookcount . ""; + if ($pendingbookcount != "0" || $pendingbookcount != 0) { + $plink = "" . $pendingbookcount . ""; + $pendingbookcount = $plink; + } else { + $pendingbookcount = $pendingbookcount; + } + } + $item = array( + $pendingbookcount + ); + array_push($rows, $item); + } else { + //For Python TBC + db_set_active($foss_detail->foss_name); //Active other database + $query5 = db_select('tbc_book'); + $query5->addExpression('count(*)', 'count'); + $query5->condition('approved', 1, '<>'); + //$query5->condition('author', '%'.$extrafilter.'%', 'LIKE'); + $result5 = $query5->execute(); + $pendingbookcount = $result5->fetchObject()->count; + if ($foss_detail->tbc_pending != "" && $foss_detail->tbc_pending != null && $link_flag != 1) { + $plink = "" . $pendingbookcount . ""; + $pendingbookcount = $plink; + } + $item = array( + $pendingbookcount + ); + array_push($rows, $item); + } + } else { + $headers = array( + "Labs in Progress" + ); + $query = db_select('foss_type'); + $query->fields('foss_type', array( + 'id' + )); + $query->fields('foss_type', array( + 'foss_name' + )); + $query->fields('foss_type', array( + 'lab_migration' + )); + $query->fields('foss_type', array( + 'lm_pending' + )); + $query->condition('foss_name', $foss_type); + $query->condition('lab_migration', 1); + $result = $query->execute(); + $foss_detail = $result->fetchObject(); + db_set_active($foss_detail->foss_name); //Active other database + $query2 = db_query("SELECT COUNT(*) AS count from lab_migration_proposal WHERE approval_status=1 AND city LIKE :city AND state LIKE :state AND country LIKE :country AND FROM_UNIXTIME(approval_date) >=:startdate AND FROM_UNIXTIME(approval_date) <=:enddate", array( + ':city' => $cityname, + ':state' => $statename, + ':country' => $countryname, + ':startdate' => $startdate, + ':enddate' => $enddate + )); + $pendinglabcount = $query2->fetchObject()->count; + if ($foss_detail->lm_pending != "" && $foss_detail->lm_pending != null && $link_flag != 1) { + //$plink = "" . $pendinglabcount . ""; + if ($pendinglabcount != "0" || $pendinglabcount != 0) { + $plink = "" . $pendinglabcount . ""; + $pendinglabcount = $plink; + } else { + $pendinglabcount = $pendinglabcount; + } + + } + $item = array( + $pendinglabcount + ); + array_push($rows, $item); + } + db_set_active('default'); // We need to call the main (drupal) db back + db_set_active(); // without the paramater means set back to the default for the site + $count = bootstrap_table_format($headers, $rows); + } + return $count; +} + +//Get the list of State according to country selection .It is ajax method for state +function ajax_state_list_dependent_dropdown_callback($form, &$form_state) +{ + $foss_type = $form['foss_type']['#options'][$form_state['values']['foss_type']]; + $foss_sub_project = $form['foss_sub_project']['#options'][$form_state['values']['foss_sub_project']]; + $country = $form['countryname']['#options'][$form_state['values']['countryname']]; + + $options = array(); + if($country!="--------------"){ + if ($foss_sub_project == "Textbook Companion") { + $sub_project = "textbook_companion_proposal"; + + db_set_active($foss_type); //Active other database + + $options[0] = '--------------'; + $query = " + SELECT * FROM " . $sub_project . " + WHERE country = :country + "; + $args = array( + ":country" => $country + ); + $result = db_query($query, $args); + while ($state_detail = $result->fetchObject()) { + $options[$state_detail->state] = $state_detail->state; + } + + } else if ($foss_sub_project == "Lab Migration") { + $sub_project = "lab_migration_proposal"; + + db_set_active($foss_type); //Active other database + //$options = array(); + $options[0] = '--------------'; + $query = " + SELECT * FROM " . $sub_project . " + WHERE country = :country + "; + $args = array( + ":country" => $country + ); + $result = db_query($query, $args); + while ($state_detail = $result->fetchObject()) { + $options[$state_detail->state] = $state_detail->state; + } + + } else if ($foss_sub_project == "Workshop") { + $sub_project = "workshop"; + $foss_type_db = 'default'; + + db_set_active($foss_type_db); //Active other database + //$options = array(); + $options[0] = '--------------'; + $query = " + SELECT * FROM " . $sub_project . " + WHERE country = :country and foss_name = :foss_name + "; + $args = array( + ":country" => $country, + ":foss_name" => $foss_type + ); + $result = db_query($query, $args); + while ($state_detail = $result->fetchObject()) { + $options[$state_detail->state] = $state_detail->state; + } + }else if ($foss_sub_project == "Conference") { + $sub_project = "workshop"; + $foss_type_db = 'default'; + + db_set_active($foss_type_db); //Active other database + //$options = array(); + $options[0] = '--------------'; + $query = " + SELECT * FROM " . $sub_project . " + WHERE country = :country and foss_name = :foss_name + "; + $args = array( + ":country" => $country, + ":foss_name" => $foss_type + ); + $result = db_query($query, $args); + while ($state_detail = $result->fetchObject()) { + $options[$state_detail->state] = $state_detail->state; + } + } +else if ($foss_sub_project == "Self Workshop"){ + + + //Get self workshop foss number for spoken + + $query = db_select('foss_type'); + $query->fields('foss_type', array( + 'id' + )); + $query->fields('foss_type', array( + 'foss_name' + )); + $query->fields('foss_type', array( + 'foss_selfworkshop_no' + )); + $query->condition('foss_name', $foss_type); + $result = $query->execute(); + $foss_detail = $result->fetchObject(); + $foss_selfworkshop_no=$foss_detail->foss_selfworkshop_no; + + db_set_active('selfworkshop'); //Active other database + $options[0] = '--------------'; + $query = "SELECT distinct (s.name) as state FROM events_training t, events_academiccenter ac, events_city c, events_state s WHERE t.academic_id=ac.id and ac.city_id=c.id and c.state_id=s.id and (t.status = 4 AND t.foss_id = :foss_id ) + "; + $args = array( + ":foss_id" => $foss_selfworkshop_no, + ); + $result = db_query($query, $args); + + while ($state_detail = $result->fetchObject()) { + $options[$state_detail->state] = $state_detail->state; + + } + + } + }else{ + $options[0] = '--------------'; + } + + db_set_active('default'); // We need to call the main (drupal) db back + + $form['statename']['#options'] = $options; + $commands[] = ajax_command_replace("#load_state", drupal_render($form['statename'])); + + $optionscity = array(); + $optionscity[0] = '--------------'; + $form['cityname']['#options'] = $optionscity; + $commands[] = ajax_command_replace("#load_city", drupal_render($form['cityname'])); + + return array( + '#type' => 'ajax', + '#commands' => $commands + ); +} + +//Get the list of City according to country selection .It is ajax method for state +function ajax_city_list_dependent_dropdown_callback($form, &$form_state) +{ + $foss_type = $form['foss_type']['#options'][$form_state['values']['foss_type']]; + $foss_sub_project = $form['foss_sub_project']['#options'][$form_state['values']['foss_sub_project']]; + $country = $form['countryname']['#options'][$form_state['values']['countryname']]; + $state = $form['statename']['#options'][$form_state['values']['statename']]; + if ($foss_sub_project == "Textbook Companion") { + $sub_project = "textbook_companion_proposal"; + + db_set_active($foss_type); //Active other database + $options = array(); + $options[0] = '--------------'; + $query = " + SELECT * FROM " . $sub_project . " + WHERE country = :country and state = :state + "; + $args = array( + ":country" => $country, + ":state" => $state + ); + $result = db_query($query, $args); + while ($city_detail = $result->fetchObject()) { + $options[$city_detail->city] = $city_detail->city; + } + + } else if ($foss_sub_project == "Lab Migration") { + $sub_project = "lab_migration_proposal"; + + db_set_active($foss_type); //Active other database + $options = array(); + $options[0] = '--------------'; + $query = " + SELECT * FROM " . $sub_project . " + WHERE country = :country and state = :state + "; + $args = array( + ":country" => $country, + ":state" => $state + ); + $result = db_query($query, $args); + while ($city_detail = $result->fetchObject()) { + $options[$city_detail->city] = $city_detail->city; + } + + } else if ($foss_sub_project == "Workshop") { + $sub_project = "workshop"; + $foss_type_db = 'default'; + + db_set_active($foss_type_db); //Active other database + $options = array(); + $options[0] = '--------------'; + $query = " + SELECT * FROM " . $sub_project . " + WHERE country = :country and state = :state and foss_name = :foss_name + "; + $args = array( + ":country" => $country, + ":state" => $state, + ":foss_name" => $foss_type + ); + $result = db_query($query, $args); + while ($city_detail = $result->fetchObject()) { + $options[$city_detail->city] = $city_detail->city; + } + }else if ($foss_sub_project == "Conference") { + $sub_project = "workshop"; + $foss_type_db = 'default'; + + db_set_active($foss_type_db); //Active other database + $options = array(); + $options[0] = '--------------'; + $query = " + SELECT * FROM " . $sub_project . " + WHERE country = :country and state = :state and foss_name = :foss_name + "; + $args = array( + ":country" => $country, + ":state" => $state, + ":foss_name" => $foss_type + ); + $result = db_query($query, $args); + while ($city_detail = $result->fetchObject()) { + $options[$city_detail->city] = $city_detail->city; + } + }else if ($foss_sub_project == "Self Workshop"){ + + //Get self workshop foss number for spoken + + $query = db_select('foss_type'); + $query->fields('foss_type', array( + 'id' + )); + $query->fields('foss_type', array( + 'foss_name' + )); + $query->fields('foss_type', array( + 'foss_selfworkshop_no' + )); + $query->condition('foss_name', $foss_type); + $result = $query->execute(); + $foss_detail = $result->fetchObject(); + $foss_selfworkshop_no=$foss_detail->foss_selfworkshop_no; + db_set_active('selfworkshop'); //Active other database + $options[0] = '--------------'; + + $query="SELECT distinct (c.name) as city FROM events_training t, events_academiccenter ac, events_city c, events_state s WHERE t.academic_id=ac.id and ac.city_id=c.id and c.state_id=s.id and (t.status = 4 AND t.foss_id = :foss_id ) and s.name LIKE :statename"; + + $args = array( + ":foss_id" => $foss_selfworkshop_no, + ":statename"=>$state, + ); + $result = db_query($query, $args); + + while ($city_detail = $result->fetchObject()) { + $options[$city_detail->city] = $city_detail->city; + + } + + } + + + db_set_active('default'); // We need to call the main (drupal) db back + + $form['cityname']['#options'] = $options; + $commands[] = ajax_command_replace("#load_city", drupal_render($form['cityname'])); + + return array( + '#type' => 'ajax', + '#commands' => $commands + ); +} + +//Get list of country +function get_country_list($foss_type, $foss_sub_project) +{ + + if ($foss_type!= 0) { + if ($foss_sub_project != 0) { + + $query = db_select('foss_type'); + $query->fields('foss_type', array( + 'id' + )); + $query->fields('foss_type', array( + 'foss_name' + )); + $query->condition('id', $foss_type); + $result = $query->execute(); + $foss_detail = $result->fetchObject(); + $foss_type_name = $foss_detail->foss_name; + $options = array(); + + if ($foss_sub_project == 1 && $foss_type!=3) { + + $sub_project = "textbook_companion_proposal"; + + db_set_active($foss_type_name); //Active other database + + $options[0] = '--------------'; + $query = " + SELECT Distinct(country) FROM " . $sub_project . " + "; + + $result = db_query($query); + while ($country_detail = $result->fetchObject()) { + $options[$country_detail->country] = $country_detail->country; + } + + + } else if ($foss_sub_project == 2 && $foss_type!=3) { + $sub_project = "lab_migration_proposal"; + + db_set_active($foss_type_name); //Active other database + // $options = array(); + $options[0] = '--------------'; + $query = " + SELECT Distinct(country) FROM " . $sub_project . " + "; + + $result = db_query($query); + while ($country_detail = $result->fetchObject()) { + $options[$country_detail->country] = $country_detail->country; + } + + } else if ($foss_sub_project == 3||$foss_sub_project == 5) { + $sub_project = "workshop"; + $foss_type_db = 'default'; + + db_set_active($foss_type_db); //Active other database + //$options = array(); + $options[0] = '--------------'; + $query = " + SELECT Distinct(country) FROM " . $sub_project . " + WHERE foss_name = :foss_name + "; + $args = array( + ":foss_name" => $foss_type_name + ); + $result = db_query($query, $args); + while ($country_detail = $result->fetchObject()) { + $options[$country_detail->country] = $country_detail->country; + } + + }else if ($foss_sub_project == 4) { + + $options[0] = '--------------'; + $options[1] = 'India'; + + } + + + db_set_active('default'); // We need to call the main (drupal) db back + + + return $options; + } else { + $options = array(); + $options[0] = '--------------'; + return $options; + } + } +} + +//Get list of state +function get_state_list($foss_type, $foss_sub_project, $country) +{ + if (($foss_type != 0) && $foss_sub_project != 0 && $country != "") { + + $query = db_select('foss_type'); + $query->fields('foss_type', array( + 'id' + )); + $query->fields('foss_type', array( + 'foss_name' + )); + $query->fields('foss_type', array( + 'foss_selfworkshop_no' + )); + $query->condition('id', $foss_type); + $result = $query->execute(); + $foss_detail = $result->fetchObject(); + $foss_type_name = $foss_detail->foss_name; + $foss_selfworkshop_no=$foss_detail->foss_selfworkshop_no; + $options = array(); + + if ($foss_sub_project == 1 && $foss_type!=3) { + $options = array(); + $sub_project = "textbook_companion_proposal"; + + db_set_active($foss_type_name); //Active other database + + $options[0] = '--------------'; + $query = " + SELECT * FROM " . $sub_project . " + WHERE country = :country + "; + $args = array( + ":country" => $country + ); + $result = db_query($query, $args); + while ($state_detail = $result->fetchObject()) { + $options[$state_detail->state] = $state_detail->state; + } + + } else if ($foss_sub_project == 2 && $foss_type!=3) { + $sub_project = "lab_migration_proposal"; + $options = array(); + db_set_active($foss_type_name); //Active other database + + $options[0] = '--------------'; + $query = " + SELECT * FROM " . $sub_project . " + WHERE country = :country + "; + $args = array( + ":country" => $country + ); + $result = db_query($query, $args); + while ($state_detail = $result->fetchObject()) { + $options[$state_detail->state] = $state_detail->state; + } + + } else if ($foss_sub_project == 3||$foss_sub_project == 5) { +$options = array(); + $sub_project = "workshop"; + $foss_type_db = 'default'; + + db_set_active($foss_type_db); //Active other database + + $options[0] = '--------------'; + $query = "SELECT * FROM " . $sub_project . " + WHERE country = :country and foss_name = :foss_name + "; + $args = array( + ":country" => $country, + ":foss_name" => $foss_type_name + ); + $result = db_query($query, $args); + while ($state_detail = $result->fetchObject()) { + $options[$state_detail->state] = $state_detail->state; + } + + } else if ($foss_sub_project == 4) { + + db_set_active('selfworkshop'); //Active other database + $options[0] = '--------------'; + $query = "SELECT distinct (s.name) as state FROM events_training t, events_academiccenter ac, events_city c, events_state s WHERE t.academic_id=ac.id and ac.city_id=c.id and c.state_id=s.id and (t.status = 4 AND t.foss_id = :foss_id ) + "; + $args = array( + ":foss_id" => $foss_selfworkshop_no, + ); + $result = db_query($query, $args); + + while ($state_detail = $result->fetchObject()) { + $options[$state_detail->state] = $state_detail->state; + + } + + } + db_set_active('default'); // We need to call the main (drupal) db back + + return $options; + } else { + $options = array(); + $options[0] = '--------------'; + return $options; + } +} +//Get List of City +function get_city_list($foss_type, $foss_sub_project, $country, $state) +{ + + if (($foss_type != 0 ) && $foss_sub_project != 0 && $country != "" && $state != "") { + + $query = db_select('foss_type'); + $query->fields('foss_type', array( + 'id' + )); + $query->fields('foss_type', array( + 'foss_name' + )); + $query->fields('foss_type', array( + 'foss_selfworkshop_no' + )); + $query->condition('id', $foss_type); + $result = $query->execute(); + $foss_detail = $result->fetchObject(); + $foss_type = $foss_detail->foss_name; + $foss_selfworkshop_no=$foss_detail->foss_selfworkshop_no; + if ($foss_sub_project == 1 && $foss_type!=3) { + $sub_project = "textbook_companion_proposal"; + db_set_active($foss_type); //Active other database + $options = array(); + $options[0] = '--------------'; + $query = " + SELECT * FROM " . $sub_project . " + WHERE country = :country and state = :state + "; + $args = array( + ":country" => $country, + ":state" => $state + ); + $result = db_query($query, $args); + while ($city_detail = $result->fetchObject()) { + $options[$city_detail->city] = $city_detail->city; + } + + } else if ($foss_sub_project == 2 && $foss_type!=3) { + $sub_project = "lab_migration_proposal"; + db_set_active($foss_type); //Active other database + $options = array(); + $options[0] = '--------------'; + $query = " + SELECT * FROM " . $sub_project . " + WHERE country = :country and state = :state + "; + $args = array( + ":country" => $country, + ":state" => $state + ); + $result = db_query($query, $args); + while ($city_detail = $result->fetchObject()) { + $options[$city_detail->city] = $city_detail->city; + } + + + } else if ($foss_sub_project == 3||$foss_sub_project == 5) { + $sub_project = "workshop"; + $foss_type_db = 'default'; + + db_set_active($foss_type_db); //Active other database + $options = array(); + $options[0] = '--------------'; + $query = " + SELECT * FROM " . $sub_project . " + WHERE country = :country and state = :state and foss_name = :foss_name + "; + $args = array( + ":country" => $country, + ":state" => $state, + ":foss_name" => $foss_type + ); + $result = db_query($query, $args); + while ($city_detail = $result->fetchObject()) { + $options[$city_detail->city] = $city_detail->city; + } + } else if ($foss_sub_project == 4) { + + + db_set_active('selfworkshop'); //Active other database + $options[0] = '--------------'; + + $query="SELECT distinct (c.name) as city FROM events_training t, events_academiccenter ac, events_city c, events_state s WHERE t.academic_id=ac.id and ac.city_id=c.id and c.state_id=s.id and (t.status = 4 AND t.foss_id = :foss_id ) and s.name LIKE :statename"; + + $args = array( + ":foss_id" => $foss_selfworkshop_no, + ":statename"=>$state, + ); + $result = db_query($query, $args); + + while ($city_detail = $result->fetchObject()) { + $options[$city_detail->city] = $city_detail->city; + + } + } + + + + db_set_active('default'); // We need to call the main (drupal) db back + + + return $options; + } else { + $options = array(); + $options[0] = '--------------'; + return $options; + } +} + +/*Add Event form (Workshop and seminar aling with photos testimonials and speakers) + Same form is used for editing existing events +*/ +function workshop_add_form($form, &$form_state, $workshop_id = 0, $no_js_use = FALSE) +{ + +$query = " + SELECT * FROM workshop + WHERE w_id = :workshop_id + "; + $args = array( + ":workshop_id" => $workshop_id + ); + $result = db_query($query, $args); + $row = $result->fetchObject(); + $form = array(); + + if ($workshop_id == 0) { + $form['foss_select'] = array( + '#type' => 'select', + '#title' => t('Select FOSS under which event took place '), + '#options' => get_first_dropdown_options_foss_name(), + '#default_value' => '', + "#required" => TRUE + ); + $form['type'] = array( + '#type' => 'select', + '#title' => t('Selected Type'), + '#options' => array( + 'Workshop' => t('Workshop'), + 'Conference' => t('Conference'), + 'Events' => t('Events') + ), + '#default_value' => '', + "#required" => TRUE + ); + $form["name"] = array( + "#type" => "textfield", + "#title" => "Name", + "#default_value" => '', + "#required" => TRUE + ); + $form['start_date'] = array( + '#type' => 'date_popup', + '#title' => t('Select Start Date Of Event :'), + '#date_increment' => 15, + '#date_year_range' => '2008:+3', + '#default_value' => '', + '#date_format' => 'Y-m-d', + '#attributes' => array( + 'autocomplete' => 'off', + 'readonly' => 'readonly' + ), + "#required" => TRUE + ); + $form['end_date'] = array( + '#type' => 'date_popup', + '#title' => t('Select End Date Of Event:'), + '#date_increment' => 15, + '#date_year_range' => '2008:+3', + '#default_value' => '', + '#date_format' => 'Y-m-d', + '#attributes' => array( + 'autocomplete' => 'off', + 'readonly' => 'readonly' + ), + "#required" => TRUE + ); + $form["venue"] = array( + "#type" => "textfield", + "#title" => "Venue", + "#default_value" => '', + "#required" => TRUE + ); + $form["street"] = array( + "#type" => "textfield", + "#title" => "Street", + "#default_value" => '', + "#required" => TRUE + ); + $form['country'] = array( + '#type' => 'select', + '#title' => t('Country'), + '#options' => array( + 'India' => 'India', + 'Others' => 'Others' + ), + '#required' => TRUE, + '#tree' => TRUE, + '#validated' => TRUE + ); + $form['other_country'] = array( + '#type' => 'textfield', + '#title' => t('Other than India'), + '#size' => 100, + '#attributes' => array( + 'placeholder' => t('Enter your country name') + ), + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array( + 'value' => 'Others' + ) + ) + ) + ); + $form['other_state'] = array( + '#type' => 'textfield', + '#title' => t('State other than India'), + '#size' => 100, + '#attributes' => array( + 'placeholder' => t('Enter your state/region name') + ), + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array( + 'value' => 'Others' + ) + ) + ) + ); + $form['other_city'] = array( + '#type' => 'textfield', + '#title' => t('City other than India'), + '#size' => 100, + '#attributes' => array( + 'placeholder' => t('Enter your city name') + ), + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array( + 'value' => 'Others' + ) + ) + ) + ); + $form['all_state'] = array( + '#type' => 'select', + '#title' => t('State'), + '#options' => _list_of_states(), + '#validated' => TRUE, + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array( + 'value' => 'India' + ) + ) + ) + ); + $form['city'] = array( + '#type' => 'select', + '#title' => t('City'), + '#options' => _list_of_cities(), + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array( + 'value' => 'India' + ) + ) + ) + ); + $form['pincode'] = array( + '#type' => 'textfield', + '#title' => t('Pincode'), + '#size' => 30, + '#maxlength' => 6, + '#required' => False, + '#attributes' => array( + 'placeholder' => 'Enter pincode....' + ) + ); + + $form["no_of_participant"] = array( + "#type" => "textfield", + "#title" => "Number Of Participants", + "#default_value" => '', + "#required" => TRUE + ); + $form["body"] = array( + "#type" => "textarea", + "#title" => "Details", + "#default_value" => '', + "#required" => TRUE + ); + $form['speakers_fieldset'] = array( + '#type' => 'fieldset', + '#tree' => TRUE, + '#prefix' => '
', + '#suffix' => '
' + ); + if (empty($form_state['num_speakers'])) { + $form_state['num_speakers'] = 1; + } + $temp = 0; + for ($i = 0; $i < $form_state['num_speakers']; $i++) { + $temp1 = $i; + $form['speakers_fieldset'][$i]["s_text"] = array( + "#type" => "item", + "#markup" => "

" + ); + $form['speakers_fieldset'][$i]["speakername"] = array( + "#type" => "textfield", + "#title" => "Name", + "#default_value" => "" + ); + $form['speakers_fieldset'][$i]["institute"] = array( + "#type" => "textfield", + "#title" => "Institute", + "#default_value" => "" + ); + $form['speakers_fieldset'][$i]["place"] = array( + "#type" => "textfield", + "#title" => "Place", + "#default_value" => "" + ); + } + $form["speakers_count"] = array( + "#type" => "hidden", + "#value" => $temp1 + ); + $form['speakers_fieldset']['add_speakers'] = array( + '#type' => 'submit', + '#value' => t('Add Speaker'), + '#limit_validation_errors' => array(), + '#submit' => array( + 'speakers_add_more_add_one' + ), + '#ajax' => array( + 'callback' => 'speakers_add_more_callback', + 'wrapper' => 'speakers-fieldset-wrapper' + ) + ); + if ($form_state['num_speakers'] > 1) { + $form['speakers_fieldset']['remove_speakers'] = array( + '#type' => 'submit', + '#value' => t('Remove Speaker'), + '#limit_validation_errors' => array(), + '#submit' => array( + 'speakers_add_more_remove_one' + ), + '#ajax' => array( + 'callback' => 'speakers_add_more_callback', + 'wrapper' => 'speakers-fieldset-wrapper' + ) + ); + } + if ($no_js_use) { + if (!empty($form['speakers_fieldset']['remove_speakers']['#ajax'])) { + unset($form['speakers_fieldset']['remove_speakers']['#ajax']); + } + unset($form['speakers_fieldset']['add_speakers']['#ajax']); + } + $form['testimonial_fieldset'] = array( + '#type' => 'fieldset', + '#tree' => TRUE, + '#prefix' => '
', + '#suffix' => '
' + ); + if (empty($form_state['num_testimonial'])) { + $form_state['num_testimonial'] = 1; + } + $temp = 0; + for ($i = 0; $i < $form_state['num_testimonial']; $i++) { + $temp = $i; + $form['testimonial_fieldset'][$i]["t_text"] = array( + "#type" => "item", + "#markup" => "

" + ); + $form['testimonial_fieldset'][$i]["t_name"] = array( + "#type" => "textfield", + "#title" => "Name", + "#default_value" => "" + ); + $form['testimonial_fieldset'][$i]["t_department"] = array( + "#type" => "textfield", + "#title" => "Department", + "#default_value" => "" + ); + $form['testimonial_fieldset'][$i]["t_university"] = array( + "#type" => "textfield", + "#title" => "University", + "#default_value" => "" + ); + $form['testimonial_fieldset'][$i]["t_body"] = array( + "#type" => "textarea", + "#title" => "Testimonial" + ); + } + $form["testimonial_count"] = array( + "#type" => "hidden", + "#value" => $temp + ); + $form['testimonial_fieldset']['add_testimonial'] = array( + '#type' => 'submit', + '#value' => t('Add Testimonial'), + '#limit_validation_errors' => array(), + '#submit' => array( + 'testimonial_add_more_add_one' + ), + '#ajax' => array( + 'callback' => 'testimonial_add_more_callback', + 'wrapper' => 'testimonial-fieldset-wrapper' + ) + ); + if ($form_state['num_testimonial'] > 1) { + $form['testimonial_fieldset']['remove_testimonial'] = array( + '#type' => 'submit', + '#value' => t('Remove Testimonial'), + '#limit_validation_errors' => array(), + '#submit' => array( + 'testimonial_add_more_remove_one' + ), + '#ajax' => array( + 'callback' => 'testimonial_add_more_callback', + 'wrapper' => 'testimonial-fieldset-wrapper' + ) + ); + } + if ($no_js_use) { + if (!empty($form['testimonial_fieldset']['remove_testimonial']['#ajax'])) { + unset($form['testimonial_fieldset']['remove_testimonial']['#ajax']); + } + unset($form['testimonial_fieldset']['add_testimonial']['#ajax']); + } + $form['names_fieldset'] = array( + '#type' => 'fieldset', + '#tree' => TRUE, + '#prefix' => '
', + '#suffix' => '
' + ); + if (empty($form_state['num_names'])) { + $form_state['num_names'] = 1; + } + for ($i = 0; $i < $form_state['num_names']; $i++) { + $form['names_fieldset'][$i]['name'] = array( + '#title' => t('Add Event Image'), + '#type' => 'file', + '#weight' => '5', + '#description' => t('Upload an image'), + // We need this to know which file element this is. + // By default drupal would name all as files[names_fieldset] + '#name' => 'files[names_fieldset_' . $i . '_name]' + ); + } + $form['names_fieldset']['add_name'] = array( + '#type' => 'submit', + '#value' => t('Add Image'), + '#limit_validation_errors' => array(), + '#submit' => array( + 'workshop_add_more_add_one' + ), + '#ajax' => array( + 'callback' => 'workshop_add_more_callback', + 'wrapper' => 'names-fieldset-wrapper' + ) + ); + if ($form_state['num_names'] > 1) { + $form['names_fieldset']['remove_name'] = array( + '#type' => 'submit', + '#value' => t('Remove Image'), + '#limit_validation_errors' => array(), + '#submit' => array( + 'workshop_add_more_remove_one' + ), + '#ajax' => array( + 'callback' => 'workshop_add_more_callback', + 'wrapper' => 'names-fieldset-wrapper' + ) + ); + } + if ($no_js_use) { + if (!empty($form['names_fieldset']['remove_name']['#ajax'])) { + unset($form['names_fieldset']['remove_name']['#ajax']); + } + unset($form['names_fieldset']['add_name']['#ajax']); + } + } else { + $form = array(); + $form['foss_select'] = array( + '#type' => 'select', + '#title' => t('Select FOSS under which event took place '), + '#options' => get_first_dropdown_options_foss_name(), + '#default_value' => $row->foss_name, + "#required" => TRUE + ); + $form['type'] = array( + '#type' => 'select', + '#title' => t('Selected Type'), + '#options' => array( + 'Workshop' => t('Workshop'), + 'Conference' => t('Conference'), + 'Events' => t('Events') + ), + '#default_value' => $row->type, + "#required" => TRUE + ); + $form["name"] = array( + "#type" => "textfield", + "#title" => "Name", + "#default_value" => $row->w_name, + "#required" => TRUE + ); + $form['start_date'] = array( + '#type' => 'date_popup', + '#title' => t('Select Start Date Of Event :'), + '#date_increment' => 15, + '#date_year_range' => '2008:+3', + '#default_value' => $row->startdate, + '#date_format' => 'Y-m-d', + '#attributes' => array( + 'autocomplete' => 'off', + 'readonly' => 'readonly' + ), + "#required" => TRUE + ); + $form['end_date'] = array( + '#type' => 'date_popup', + '#title' => t('Select End Date Of Event:'), + '#date_increment' => 15, + '#date_year_range' => '2008:+3', + '#default_value' => $row->enddate, + '#date_format' => 'Y-m-d', + '#attributes' => array( + 'autocomplete' => 'off', + 'readonly' => 'readonly' + ), + "#required" => TRUE + ); + $form["venue"] = array( + "#type" => "textfield", + "#title" => "Venue", + "#default_value" => $row->venue, + "#required" => TRUE + ); + $form["street"] = array( + "#type" => "textfield", + "#title" => "Street", + "#default_value" => $row->street, + "#required" => TRUE + ); + $form['country'] = array( + '#type' => 'select', + '#title' => t('Country'), + '#options' => array( + 'India' => 'India', + 'Others' => 'Others' + ), + '#required' => TRUE, + '#tree' => TRUE, + '#validated' => TRUE, + "#default_value" => $row->country + ); + $form['other_country'] = array( + '#type' => 'textfield', + '#title' => t('Other than India'), + '#size' => 100, + '#attributes' => array( + 'placeholder' => t('Enter your country name') + ), + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array( + 'value' => 'Others' + ) + ) + ), + "#default_value" => $row->country + ); + $form['other_state'] = array( + '#type' => 'textfield', + '#title' => t('State other than India'), + '#size' => 100, + '#attributes' => array( + 'placeholder' => t('Enter your state/region name') + ), + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array( + 'value' => 'Others' + ) + ) + ), + "#default_value" => $row->state + ); + $form['other_city'] = array( + '#type' => 'textfield', + '#title' => t('City other than India'), + '#size' => 100, + '#attributes' => array( + 'placeholder' => t('Enter your city name') + ), + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array( + 'value' => 'Others' + ) + ) + ), + "#default_value" => $row->city + ); + $form['all_state'] = array( + '#type' => 'select', + '#title' => t('State'), + '#options' => _list_of_states(), + '#validated' => TRUE, + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array( + 'value' => 'India' + ) + ) + ), + "#default_value" => $row->state + ); + $form['city'] = array( + '#type' => 'select', + '#title' => t('City'), + '#options' => _list_of_cities(), + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array( + 'value' => 'India' + ) + ) + ), + "#default_value" => $row->city + ); + $form['pincode'] = array( + '#type' => 'textfield', + '#title' => t('Pincode'), + '#size' => 30, + '#maxlength' => 6, + '#required' => False, + '#attributes' => array( + 'placeholder' => 'Enter pincode....' + ), + "#default_value" => $row->pincode + ); + $form["no_of_participant"] = array( + "#type" => "textfield", + "#title" => "Number Of Participants", + "#default_value" => $row->no_of_participant, + "#required" => TRUE + ); + $form["body"] = array( + "#type" => "textarea", + "#title" => "Details", + "#default_value" => $row->body, + "#required" => TRUE + ); + /*Edit Speakers*/ + /*Edit Testimonial*/ + $query_t = db_select('testimonials'); + $query_t->fields('testimonials'); + $query_t->condition('w_id', $workshop_id); + $result_t = $query_t->execute(); + $num_of_results = $result_t->rowCount(); + $form['testimonial_fieldset'] = array( + '#type' => 'fieldset', + '#tree' => TRUE, + //'#title' => t('Add Testimonial'), + '#prefix' => '
', + '#suffix' => '
' + ); + if ($num_of_results != 0) { + $form_state['num_testimonial'] = $num_of_results; + $temp = 0; + $i = 0; + while ($row_t = $result_t->fetchObject()) { + $temp = $i; + $form['testimonial_fieldset'][$i]["t_text"] = array( + "#type" => "item", + "#markup" => "

" + ); + $form['testimonial_fieldset'][$i]["t_id"] = array( + "#type" => "hidden", + "#default_value" => $row_t->t_id + ); + $form['testimonial_fieldset'][$i]["t_name"] = array( + "#type" => "textfield", + "#title" => "Name", + "#default_value" => $row_t->name + ); + $form['testimonial_fieldset'][$i]["t_department"] = array( + "#type" => "textfield", + "#title" => "Department", + "#default_value" => $row_t->department + ); + $form['testimonial_fieldset'][$i]["t_university"] = array( + "#type" => "textfield", + "#title" => "University", + "#default_value" => $row_t->university + ); + $form['testimonial_fieldset'][$i]["t_body"] = array( + "#type" => "textarea", + "#title" => "Testimonial", + "#default_value" => $row_t->body + ); + $i++; + } + $form["testimonial_count"] = array( + "#type" => "hidden", + "#value" => $temp + ); + } else { + if (empty($form_state['num_testimonial'])) { + $form_state['num_testimonial'] = 1; + } + $temp = 0; + for ($i = 0; $i < $form_state['num_testimonial']; $i++) { + $temp = $i; + $form['testimonial_fieldset'][$i]["t_text"] = array( + "#type" => "item", + "#markup" => "

" + ); + $form['testimonial_fieldset'][$i]["t_name"] = array( + "#type" => "textfield", + "#title" => "Name", + "#default_value" => "" + ); + $form['testimonial_fieldset'][$i]["t_department"] = array( + "#type" => "textfield", + "#title" => "Department", + "#default_value" => "" + ); + $form['testimonial_fieldset'][$i]["t_university"] = array( + "#type" => "textfield", + "#title" => "University", + "#default_value" => "" + ); + $form['testimonial_fieldset'][$i]["t_body"] = array( + "#type" => "textarea", + "#title" => "Testimonial" + ); + } + $form["testimonial_count"] = array( + "#type" => "hidden", + "#value" => $temp + ); + $form['testimonial_fieldset']['add_testimonial'] = array( + '#type' => 'submit', + '#value' => t('Add testimonial'), + '#limit_validation_errors' => array(), + '#submit' => array( + 'testimonial_add_more_add_one' + ), + '#ajax' => array( + 'callback' => 'testimonial_add_more_callback', + 'wrapper' => 'testimonial-fieldset-wrapper' + ) + ); + if ($form_state['num_testimonial'] > 1) { + $form['testimonial_fieldset']['remove_testimonial'] = array( + '#type' => 'submit', + '#value' => t('Remove'), + '#limit_validation_errors' => array(), + '#submit' => array( + 'testimonial_add_more_remove_one' + ), + '#ajax' => array( + 'callback' => 'testimonial_add_more_callback', + 'wrapper' => 'testimonial-fieldset-wrapper' + ) + ); + } + if ($no_js_use) { + if (!empty($form['testimonial_fieldset']['remove_testimonial']['#ajax'])) { + unset($form['testimonial_fieldset']['remove_testimonial']['#ajax']); + } + unset($form['testimonial_fieldset']['add_testimonial']['#ajax']); + } + } + $form['uploadphotos'] = array( + '#markup' => '

Edit Photos

(Select Check box to delete existing photos)', + '#prefix' => '
', + '#suffix' => '' + ); + $query = db_select('workshop'); + $query->fields('workshop'); + $query->condition('w_id', $workshop_id); + $result = $query->execute(); + $row = $result->fetchObject(); + $query1 = db_select('workshop_images'); + $query1->fields('workshop_images'); + $query1->condition('w_id', $workshop_id); + $result1 = $query1->execute(); + while ($row1 = $result1->fetchObject()) { + $form['imagecheck@' . $row1->id] = array( + '#type' => 'checkbox', + '#field_suffix' => 'w_name) . "/" . $row1->name . ' />' + ); + } + $form['enduploadphotos'] = array( + '#markup' => '', + '#prefix' => '', + '#suffix' => '
' + ); + + $form['names_fieldset'] = array( + '#type' => 'fieldset', + '#tree' => TRUE, + // '#title' => t('Add images'), + '#prefix' => '
', + '#suffix' => '
' + ); + if (empty($form_state['num_names'])) { + $form_state['num_names'] = 1; + } + for ($i = 0; $i < $form_state['num_names']; $i++) { + $form['names_fieldset'][$i]['name'] = array( + '#title' => t('Add Event Image'), + '#type' => 'file', + '#weight' => '5', + '#description' => t('Upload an image'), + // We need this to know which file element this is. + // By default drupal would name all as files[names_fieldset] + '#name' => 'files[names_fieldset_' . $i . '_name]' + ); + } + $form['names_fieldset']['add_name'] = array( + '#type' => 'submit', + '#value' => t('Add one more'), + '#limit_validation_errors' => array(), + '#submit' => array( + 'workshop_add_more_add_one' + ), + '#ajax' => array( + 'callback' => 'workshop_add_more_callback', + 'wrapper' => 'names-fieldset-wrapper' + ) + ); + if ($form_state['num_names'] > 1) { + $form['names_fieldset']['remove_name'] = array( + '#type' => 'submit', + '#value' => t('Remove one'), + '#limit_validation_errors' => array(), + '#submit' => array( + 'workshop_add_more_remove_one' + ), + '#ajax' => array( + 'callback' => 'workshop_add_more_callback', + 'wrapper' => 'names-fieldset-wrapper' + ) + ); + } + if ($no_js_use) { + if (!empty($form['names_fieldset']['remove_name']['#ajax'])) { + unset($form['names_fieldset']['remove_name']['#ajax']); + } + unset($form['names_fieldset']['add_name']['#ajax']); + } + } + $form["workshop_id"] = array( + "#type" => "hidden", + "#value" => $workshop_id + ); + $form["submit"] = array( + "#type" => "submit", + "#value" => "Submit" + ); + return $form; +} + + +function workshop_add_form_validate($form, &$form_state) +{ + if ($form_state['values']['country'] == 'Others') { + if ($form_state['values']['other_country'] == '') { + form_set_error('other_country', t('Enter country name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + } else { + $form_state['values']['country'] = $form_state['values']['other_country']; + } + if ($form_state['values']['other_state'] == '') { + form_set_error('other_state', t('Enter state name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + } else { + $form_state['values']['all_state'] = $form_state['values']['other_state']; + } + if ($form_state['values']['other_city'] == '') { + form_set_error('other_city', t('Enter city name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + } else { + $form_state['values']['city'] = $form_state['values']['other_city']; + } + } else { + if ($form_state['values']['country'] == '') { + form_set_error('country', t('Select country name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + } + if ($form_state['values']['all_state'] == '') { + form_set_error('all_state', t('Select state name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + } + if ($form_state['values']['city'] == '') { + form_set_error('city', t('Select city name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + } + } + 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, 'names_fieldset')) + $file_type = 'I'; + switch ($file_type) { + case 'I': + $allowed_extensions_str = variable_get('events_image_extensions', ''); + break; + } + $allowed_extensions = explode(',', $allowed_extensions_str); + $temp_extension = end(explode('.', strtolower($_FILES['files']['name'][$file_form_name]))); + 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.')); + } + } + } +} + + +function speakers_add_more_callback($form, $form_state) +{ + return $form['speakers_fieldset']; +} + + +function speakers_add_more_add_one($form, &$form_state) +{ + $form_state['num_speakers']++; + $form_state['rebuild'] = TRUE; + //$form_state['no_redirect'] = TRUE; +} + + +function speakers_add_more_remove_one($form, &$form_state) +{ + if ($form_state['num_speakers'] > 1) { + $form_state['num_speakers']--; + } + $form_state['rebuild'] = TRUE; +} + + +function testimonial_add_more_callback($form, $form_state) +{ + return $form['testimonial_fieldset']; +} + + +function testimonial_add_more_add_one($form, &$form_state) +{ + $form_state['num_testimonial']++; + $form_state['rebuild'] = TRUE; + //$form_state['no_redirect'] = TRUE; +} + + +function testimonial_add_more_remove_one($form, &$form_state) +{ + if ($form_state['num_testimonial'] > 1) { + $form_state['num_testimonial']--; + } + $form_state['rebuild'] = TRUE; +} + + +function workshop_add_more_callback($form, $form_state) +{ + return $form['names_fieldset']; +} + + +function workshop_add_more_add_one($form, &$form_state) +{ + $form_state['num_names']++; + $form_state['rebuild'] = TRUE; + //$form_state['no_redirect'] = TRUE; +} + + +function workshop_add_more_remove_one($form, &$form_state) +{ + if ($form_state['num_names'] > 1) { + $form_state['num_names']--; + } + $form_state['rebuild'] = TRUE; +} + + +function workshop_display_all() +{ + $page_content = ""; + $workshop_add_form = drupal_get_form("workshop_add_form"); + $page_content = drupal_render($workshop_add_form); + return $page_content; +} + + +function get_first_dropdown_options_foss_name() +{ + $query = db_select('foss_type'); + $query->fields('foss_type', array( + 'id' + )); + $query->fields('foss_type', array( + 'foss_name' + )); + $result = $query->execute(); + $options = array(); + while ($foss_detail = $result->fetchObject()) { + $options[$foss_detail->foss_name] = $foss_detail->foss_name; + } + $options["Others"] = "Others"; + return $options; +} + + +function get_country_dropdown_options() +{ + $query = db_select('Country'); + $query->fields('Country', array( + 'Code' + )); + $query->fields('Country', array( + 'Name' + )); + $result = $query->execute(); + $options = array(); + while ($country_detail = $result->fetchObject()) { + $options[$country_detail->Code] = $country_detail->Name; + } + return $options; +} + + +function workshop_add_form_submit($form, &$form_state) +{ + $v = $form_state["values"]; + //$start_datetime= explode(" ",$v["start_date"]); + //$end_datetime= explode(" ",$v["end_date"]); + if ($v["workshop_id"]) { + $query = db_update('workshop'); + $query->fields(array( + 'foss_name' => $v["foss_select"], + 'w_name' => $v["name"], + 'type' => $v["type"], + 'startdate' => $v["start_date"], + 'starttime' => "00:00", + 'enddate' => $v["end_date"], + 'endtime' => "00:00", + 'venue' => $v["venue"], + 'street' => $v["street"], + 'country' => $v["country"], + 'state' => $v["all_state"], + 'city' => $v["city"], + 'pincode' => $v["pincode"], + 'no_of_participant' => $v["no_of_participant"], + 'body' => $v["body"] + )); + $query->condition('w_id', $v["workshop_id"]); + $result = $query->execute(); + /* For editing Testimonials */ + $testimonialupload = 0; + for ($i = 0; $i <= $v["testimonial_count"]; $i++) { + if ($v['testimonial_fieldset'][$i]["t_id"] != "") { + if ($v['testimonial_fieldset'][$i]["t_name"] != "") { + $query = db_update('testimonials'); + $query->fields(array( + 'body' => $v['testimonial_fieldset'][$i]["t_body"], + 'name' => $v['testimonial_fieldset'][$i]["t_name"], + 'department' => $v['testimonial_fieldset'][$i]["t_department"], + 'university' => $v['testimonial_fieldset'][$i]["t_university"] + )); + $query->condition('t_id', $v['testimonial_fieldset'][$i]["t_id"]); + $result = $query->execute(); + if ($result != 0) { + $testimonialupload++; + } + } + } else { + if ($v['testimonial_fieldset'][$i]["t_name"] != "") { + $testimonialquery = " + INSERT INTO testimonials + (w_id,body,name,department,university) + VALUES + (:w_id,:body,:name,:department,:university) + "; + $testimonialargs = array( + ":w_id" => $v["workshop_id"], + ":body" => $v['testimonial_fieldset'][$i]["t_body"], + ":name" => $v['testimonial_fieldset'][$i]["t_name"], + ":department" => $v['testimonial_fieldset'][$i]["t_department"], + ":university" => $v['testimonial_fieldset'][$i]["t_university"] + ); + /* storing the row id in $result */ + $testimonialresult = db_query($testimonialquery, $testimonialargs, array( + 'return' => Database::RETURN_INSERT_ID + )); + if ($testimonialresult != 0) { + $testimonialupload++; + } + } + } + } + /* For editing Event images */ + /* For deleting existing images */ + $deletecounter = 0; + $query_img = db_select('workshop_images'); + $query_img->fields('workshop_images'); + $query_img->condition('w_id', $v["workshop_id"]); + $result_img = $query_img->execute(); + $root_path=events_images_path(); + while ($row_img = $result_img->fetchObject()) { + if ($form_state['values']['imagecheck@' . $row_img->id] == 1) { + if (file_exists($root_path.$row_img->path)) { + unlink($root_path.$row_img->path); + $query2 = db_delete('workshop_images'); + $query2->condition('id', $row_img->id); + $delete_img = $query2->execute(); + if ($delete_img != 0) { + $deletecounter++; + } + } else { + drupal_set_message('Error Could not delete : ' . $filename . ', file does not exist', 'error'); + } + } + } + /* For adding more images to existing event */ + $items = array(); + $root_path = events_images_path(); + $eventfolder = str_replace(' ', '_', $v["name"]); + $dest_path = $eventfolder . '/'; + if (!is_dir($root_path . $dest_path)) { + mkdir($root_path . $dest_path); + } + /* uploading files */ + foreach ($_FILES['files']['name'] as $file_form_name => $file_name) { + if ($file_name) { + 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; + } + $imageupload = 0; + /* uploading file */ + if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name])) { + $imagequery = " + INSERT INTO workshop_images + (w_id,name,path) + VALUES + (:w_id,:name, :path) + "; + $imageargs = array( + ":w_id" => $v["workshop_id"], + ":name" => $_FILES['files']['name'][$file_form_name], + ":path" => $dest_path . $_FILES['files']['name'][$file_form_name] + ); + /* storing the row id in $result */ + $imageresult = db_query($imagequery, $imageargs, array( + 'return' => Database::RETURN_INSERT_ID + )); + if ($imageresult != 0) { + $imageupload++; + } + drupal_set_message($file_name . ' uploaded successfully.', 'status'); + } else { + drupal_set_message('Error uploading file : ' . $dest_path . $file_name, 'error'); + } + } + } + if (!$result && $imageupload == 0 && $deletecounter == 0) { + drupal_set_message("Something went wrong, please try again.", "error"); + } else { + drupal_set_message("Workshop updated successfully", "status"); + if ($imageupload != 0) { + drupal_set_message("Event's Pictures are added successfully", "status"); + } + if ($deletecounter != 0) { + drupal_set_message("Event's Pictures are deleted successfully", "status"); + } + } + } else { + $query = " + INSERT INTO workshop + (foss_name,type,w_name, startdate, starttime,enddate, endtime, venue, street, country,state,city,pincode,no_of_participant,body) + VALUES (:foss_name,:type,:w_name, :startdate, :starttime,:enddate, :endtime, :venue, :street, :country, :state, :city, :pincode, +:no_of_participant, :body) + "; + $args = array( + ":type" => $v["type"], + ":foss_name" => $v["foss_select"], + ":w_name" => $v["name"], + ":startdate" => $v["start_date"], + ":starttime" => "00:00", + ":enddate" => $v["end_date"], + ":endtime" => "00:00", + ":venue" => $v["venue"], + ":street" => $v["street"], + ":country" => $v["country"], + ":state" => $v["all_state"], + ":city" => $v["city"], + ":pincode" => $v["pincode"], + ":no_of_participant" => $v["no_of_participant"], + ":body" => $v["body"] + ); + /* storing the row id in $result */ + $result = db_query($query, $args, array( + 'return' => Database::RETURN_INSERT_ID + )); + /* For adding speakers */ + $speakerupload = 0; + for ($i = 0; $i <= $v["speakers_count"]; $i++) { + if ($v['speakers_fieldset'][$i]["speakername"] != "") { + $speakerquery = " + INSERT INTO speakers + (w_id,name,institute,place) + VALUES + (:w_id,:name,:institute,:place) + "; + $speakerargs = array( + ":w_id" => $result, + ":name" => $v['speakers_fieldset'][$i]["speakername"], + ":institute" => $v['speakers_fieldset'][$i]["institute"], + ":place" => $v['speakers_fieldset'][$i]["place"] + ); + /* storing the row id in $result */ + $speakerresult = db_query($speakerquery, $speakerargs, array( + 'return' => Database::RETURN_INSERT_ID + )); + if ($speakerresult != 0) { + $speakerupload++; + } + } + } + /* For adding testimonial */ + $testimonialupload = 0; + for ($i = 0; $i <= $v["testimonial_count"]; $i++) { + if ($v['testimonial_fieldset'][$i]["t_name"] != "") { + $testimonialquery = " + INSERT INTO testimonials + (w_id,body,name,department,university) + VALUES + (:w_id,:body,:name,:department,:university) + "; + $testimonialargs = array( + ":w_id" => $result, + ":body" => $v['testimonial_fieldset'][$i]["t_body"], + ":name" => $v['testimonial_fieldset'][$i]["t_name"], + ":department" => $v['testimonial_fieldset'][$i]["t_department"], + ":university" => $v['testimonial_fieldset'][$i]["t_university"] + ); + /* storing the row id in $result */ + $testimonialresult = db_query($testimonialquery, $testimonialargs, array( + 'return' => Database::RETURN_INSERT_ID + )); + if ($testimonialresult != 0) { + $testimonialupload++; + } + } + } + /* For adding images of events*/ + $items = array(); + $root_path = events_images_path(); + $eventfolder = str_replace(' ', '_', $v["name"]); + $dest_path = $eventfolder . '/'; + if (!is_dir($root_path . $dest_path)) { + mkdir($root_path . $dest_path); + } + /* uploading files */ + foreach ($_FILES['files']['name'] as $file_form_name => $file_name) { + if ($file_name) { + 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; + } + $imageupload = 0; + /* uploading file */ + if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name])) { + $imagequery = " + INSERT INTO workshop_images + (w_id,name,path) + VALUES + (:w_id,:name, :path) + "; + $imageargs = array( + ":w_id" => $result, + ":name" => $_FILES['files']['name'][$file_form_name], + ":path" => $dest_path . $_FILES['files']['name'][$file_form_name] + ); + /* storing the row id in $result */ + $imageresult = db_query($imagequery, $imageargs, array( + 'return' => Database::RETURN_INSERT_ID + )); + if ($imageresult != 0) { + $imageupload++; + } + drupal_set_message($file_name . ' uploaded successfully.', 'status'); + } else { + drupal_set_message('Error uploading file : ' . $dest_path . $file_name, 'error'); + } + } + } + if (!$result) { + drupal_set_message("Something went wrong, please try again.", "error"); + } else { + drupal_set_message("Workshop added successfully", "status"); + if ($imageupload != 0) { + drupal_set_message("Event's Pictures are added successfully", "status"); + } + if ($testimonialupload != 0) { + drupal_set_message("Testimonials added successfully", "status"); + } + if ($speakerupload != 0) { + drupal_set_message("Speaker's Detail are added successfully", "status"); + } + } + } +} + + +function ajax_country_dependent_dropdown_callback($form, $form_state) +{ + $country = $form_state['values']['country']; + $form['state']['#options'] = ajax_getstate_callback($country); + $commands[] = ajax_command_replace("#dropdown-state-replace", drupal_render($form['state'])); + return array( + '#type' => 'ajax', + '#commands' => $commands + ); +} + + +function ajax_state_dependent_dropdown_callback($form, $form_state) +{ + $state = $form_state['values']['state']; + $form['city']['#options'] = ajax_getcity_callback($state); + $commands[] = ajax_command_replace("#dropdown-city-replace", drupal_render($form['city'])); + return array( + '#type' => 'ajax', + '#commands' => $commands + ); +} + + +function ajax_getstate_callback($country = '') +{ + $query = " + SELECT Distinct (District) as state FROM City + WHERE CountryCode =:country order by District + "; + $args = array( + ":country" => $country + ); + $result = db_query($query, $args); + $options = array(); + while ($row = $result->fetchObject()) { + $options[$row->state] = $row->state; + } + return $options; +} + + +function ajax_getcity_callback($state = '') +{ + $query = " + SELECT Name as cityname FROM City + WHERE District =:state order by Name + "; + $args = array( + ":state" => $state + ); + $result = db_query($query, $args); + $options = array(); + while ($row = $result->fetchObject()) { + $options[$row->cityname] = $row->cityname; + } + return $options; +} + + +function workshop_view_image_all($id = 0) +{ + $page_content = ""; + $query = db_select('workshop_images'); + $query->fields('workshop_images'); + $query->condition('id', $id); + $result = $query->execute(); + $row1 = $result->fetchObject(); + $query = db_select('workshop'); + $query->fields('workshop'); + $query->condition('w_id', $row1->w_id); + $result = $query->execute(); + $row = $result->fetchObject(); + $previous = ($row1->id) - 1; + $page_content .= "" . $row1->name; + $page_content .= ""; + $page_content .= "
w_name) . "/" . $row1->name . " />
"; + $page_content .= "PREVIOUS"; + return $page_content; +} + + +function workshop_view_selected_testimonial($id = 0) +{ + $page_content = ""; + $query = db_select('testimonials'); + $query->fields('testimonials'); + $query->condition('t_id', $id); + $result = $query->execute(); + $row = $result->fetchObject(); + $page_content .= "