Advertisement
josh401

GISR Project

Feb 12th, 2016
642
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 116.94 KB | None | 0 0
  1. <?php
  2. // **************************************************************************
  3. // This file is only used for admin_panel.php in the 'views' folder.
  4. // **************************************************************************
  5. ?>
  6.  
  7. <script type="text/javascript">
  8.  
  9.     jQuery(document).ready(function($) {
  10.                    
  11.         // Set paging global for paging revisions
  12.         var paging = '';
  13.         var paging_dsah = '';
  14.        
  15.         // Hide admin message
  16.         if($("#admin_message").children().length == 0) {
  17.             $("#admin_message").hide();
  18.         }
  19.         // Set timeout if showing admin message
  20.         setTimeout(function() {
  21.             $( "#admin_message" ).slideUp( "slow", function() {
  22.                 // Animation complete.
  23.             });
  24.         }, 2000);
  25.        
  26.         // Date/Time picker
  27.         $( '#date_created' ).datetimepicker({
  28.             dateFormat: "yy-mm-dd",
  29.             timeFormat:  "HH:mm:ss"
  30.         });
  31.        
  32.         // Scroll window to top on page load
  33.         $(window).scrollTop(0);
  34.    
  35.         // jQuery tabs
  36.         $( "#tabs" ).tabs({
  37.             beforeActivate: function (event, ui) {
  38.                 window.location.hash = ui.newPanel.selector;
  39.             }
  40.         });
  41.        
  42.        
  43.         // From hashchange plugin (to keep browser history of tabs selection
  44.         // For forward and back
  45.         $.address.change(function(event){
  46.            
  47.             tab_location = 0;
  48.            
  49.             // Get tab and set number
  50.             if(window.location.hash == '#tabs-dashboard') tab_location = 0;
  51.             if(window.location.hash == '#tabs-users') tab_location = 1;
  52.             if(window.location.hash == '#tabs-companies') tab_location = 2;
  53.             if(window.location.hash == '#tabs-products') tab_location = 3;
  54.             if(window.location.hash == '#tabs-revisions') tab_location = 4;
  55.             if(window.location.hash == '#tabs-permissions') tab_location = 5;
  56.             if(window.location.hash == '#tabs-prod-fam-lookup') tab_location = 6;
  57.             if(window.location.hash == '#tabs-data-fields') tab_location = 7;
  58.             if(window.location.hash == '#tabs-misc') tab_location = 8;
  59.            
  60.             // Set active tab
  61.             $("#tabs").tabs( "option", "active", tab_location );
  62.             $(window).scrollTop(0);
  63.         });
  64.         // When the tab is selected update the url with the hash
  65.         $("#tabs").on("tabsactivate", function(event, ui) {
  66.             window.location.hash = ui.newPanel.selector;
  67.             $(window).scrollTop(0);
  68.         });
  69.        
  70.        
  71.        
  72.        
  73.         // *****************************************************************************
  74.         // Dashboard Tab
  75.         // *****************************************************************************
  76.                
  77.         // Hide pagination div and pagination date div
  78.         $('.pagination_dash').hide();
  79.         $('#pagination_date').hide();
  80.         $('#pagination_date_dropdown').hide();
  81.            
  82.         // Get current stats values
  83.         var $cur_market_comp_owners = $('#company_type_owner').html();
  84.         var $cur_market_comp_res_owners = $('#company_type_research_owner').html();
  85.         var $cur_market_comp_res_data = $('#company_type_research_data').html();
  86.         var $cur_issues_cov_environmental = $('#issue_e').html();
  87.         var $cur_issues_cov_social = $('#issue_s').html();
  88.         var $cur_issues_cov_governance = $('#issue_g').html();
  89.         var $cur_issues_cov_combined = $('#issue_esg').html();
  90.         var $cur_primary_aud_investors = $('#pa_investors').html();
  91.         var $cur_primary_aud_consumers = $('#pa_consumers').html();
  92.         var $cur_primary_aud_companies = $('#pa_companies').html();
  93.         var $cur_product_type_rating = $('#pt_rating').html();
  94.         var $cur_product_type_ranking = $('#pt_ranking').html();
  95.         var $cur_product_type_index = $('#pt_index').html();
  96.            
  97.         $('#show_comp_prod_stats_history').click(function() {
  98.            
  99.             // If we are clicking to show the history
  100.             if($(this).text() == 'Show History') {
  101.                
  102.                 // Change button text
  103.                 $(this).text('Hide History');
  104.            
  105.                 // Show export buttons
  106.                 $('#export_stats_current_page').show();
  107.                 $('#export_stats_entire_history').show();
  108.                
  109.                 // Show pagination div and pagination dropdown div
  110.                 $('.pagination_dash').show();
  111.                 $('#pagination_date').show();
  112.                 $('#pagination_date_dropdown').show();
  113.                
  114.                 // Need to run ajax to get count needed for pagination
  115.                 $.post("<?php echo base_url() . index_page(); ?>admin/count_dash_stats").done(function (data) {
  116.                    
  117.                     // Build date dropdown array variable
  118.                     var $date_dropdown_dash = [];
  119.                     $.each(data.date_dropdown, function(i, v) {
  120.                         $.each(v, function(ii, vv) {
  121.                             if(ii === 'date')
  122.                                 $date_dropdown_dash.push(vv);
  123.                         });
  124.                     });
  125.                    
  126.                     // If there are results to paginate
  127.                     if(data.count !== 0) {
  128.                        
  129.                         // Paginate results
  130.                         paging_dash = $(".pagination_dash").paging(data.count, {
  131.                            
  132.                             format: "[< - nncn - >]",
  133.                             perpage: 1,
  134.                             onSelect: function (page) {
  135.                                
  136.                                 // Declare start and end values
  137.                                 var $start = this.slice[0];
  138.                                 var $end = this.slice[1];
  139.                                
  140.                                 // Populate hidden input with $start value (will be array key of matched data)
  141.                                 $('#export_stats_current_page_marker').val($start);
  142.                                
  143.                                 // Fire ajax to get company/product revision history
  144.                                 $.post("<?php echo base_url() . index_page(); ?>admin/get_dash_history", {start: $start, end: $end}).done(function (data) {
  145.                                    
  146.                                     $date = '';
  147.                                     $market_comp_owners = '';
  148.                                     $market_comp_res_owners = '';
  149.                                     $market_comp_res_data = '';
  150.                                     $issues_cov_environmental = '';
  151.                                     $issues_cov_social = '';
  152.                                     $issues_cov_governance = '';
  153.                                     $issues_cov_combined = '';
  154.                                     $primary_aud_investors = '';
  155.                                     $primary_aud_consumers = '';
  156.                                     $primary_aud_companies = '';
  157.                                     $product_type_rating = '';
  158.                                     $product_type_ranking = '';
  159.                                     $product_type_index = '';
  160.                                    
  161.                                     $.each(data.dash_stats_history, function (i, v) {
  162.                                        
  163.                                         $.each(v, function(ii, vv) {
  164.                                            
  165.                                             if(ii == 'date') { $date = vv; }
  166.                                             if(ii == 'market_comp_owners') { $market_comp_owners = vv; }
  167.                                             if(ii == 'market_comp_res_owners') { $market_comp_res_owners = vv; }
  168.                                             if(ii == 'market_comp_res_data') { $market_comp_res_data = vv; }
  169.                                             if(ii == 'issues_cov_environmental') { $issues_cov_environmental = vv; }
  170.                                             if(ii == 'issues_cov_social') { $issues_cov_social = vv; }
  171.                                             if(ii == 'issues_cov_governance') { $issues_cov_governance = vv; }
  172.                                             if(ii == 'issues_cov_combined') { $issues_cov_combined = vv; }
  173.                                             if(ii == 'primary_aud_investors') { $primary_aud_investors = vv; }
  174.                                             if(ii == 'primary_aud_consumers') { $primary_aud_consumers = vv; }
  175.                                             if(ii == 'primary_aud_companies') { $primary_aud_companies = vv; }
  176.                                             if(ii == 'product_type_rating') { $product_type_rating = vv; }
  177.                                             if(ii == 'product_type_ranking') { $product_type_ranking = vv; }
  178.                                             if(ii == 'product_type_index') { $product_type_index = vv; }
  179.                                         });
  180.                                     });
  181.                                    
  182.                                     // Populate date dropdown
  183.                                     $date_drop_dash = '<select name="select_dash_stats_date" id="select_dash_stats_date">';
  184.                                     $date_drop_dash += '<option value="">Select Date...</option>';
  185.                                     $.each($date_dropdown_dash, function(i, v) {
  186.                                        
  187.                                         $date_drop_dash += '<option value="'+i+'">'+v+'</option>';
  188.                                     });
  189.                                     $date_drop_dash += '</select>';
  190.                                     $('#pagination_date_dropdown').html($date_drop_dash);
  191.                                    
  192.                                     // Populate date div
  193.                                     $('#pagination_date').hide().html($date).fadeIn();
  194.                                    
  195.                                     // Adjust stats figures
  196.                                     $('#company_type_owner').html($market_comp_owners);
  197.                                     $('#company_type_research_owner').html($market_comp_res_owners);
  198.                                     $('#company_type_research_data').html($market_comp_res_data);
  199.                                    
  200.                                     $('#issue_e').html($issues_cov_environmental);
  201.                                     $('#issue_s').html($issues_cov_social);
  202.                                     $('#issue_g').html($issues_cov_governance);
  203.                                     $('#issue_esg').html($issues_cov_combined);
  204.                                    
  205.                                     $('#pa_investors').html($primary_aud_investors);
  206.                                     $('#pa_consumers').html($primary_aud_consumers);
  207.                                     $('#pa_companies').html($primary_aud_companies);
  208.                                    
  209.                                     $('#pt_rating').html($product_type_rating);
  210.                                     $('#pt_ranking').html($product_type_ranking);
  211.                                     $('#pt_index').html($product_type_index);
  212.                                    
  213.                                     // Adjust class name
  214.                                     $('.dash_stats').addClass('dash_stats_active');
  215.                                 });
  216.                             },
  217.                             onFormat: function (type) {
  218.                            
  219.                                 switch (type) {
  220.                                    
  221.                                 case 'block':
  222.        
  223.                                     if (!this.active)
  224.                                         return '<span class="disabled">' + this.value + '</span>';
  225.                                     else if (this.value != this.page)
  226.                                         return '<em><a href="#' + this.value + '">' + this.value + '</a></em>';
  227.                                     return '<span class="current">' + this.value + '</span>';
  228.                        
  229.                                 case 'next':
  230.                        
  231.                                     if (this.active)
  232.                                         return '<a href="#' + this.value + '" class="next" title="Next">Next ></a>';
  233.                                     return '<span class="disabled">Next ></span>';
  234.                        
  235.                                 case 'prev':
  236.                        
  237.                                     if (this.active)
  238.                                         return '<a href="#' + this.value + '" class="prev" title="Previous">< Prev</a>';
  239.                                     return '<span class="disabled">< Prev</span>';
  240.                        
  241.                                 case 'first':
  242.                        
  243.                                     if (this.active)
  244.                                         return '<a href="#' + this.value + '" class="first" title="first">|<<</a>';
  245.                                     return '<span class="disabled">|<<</span>';
  246.                        
  247.                                 case 'last':
  248.                        
  249.                                     if (this.active)
  250.                                         return '<a href="#' + this.value + '" class="last" title="Last">>>|</a>';
  251.                                     return '<span class="disabled">>>|</span>';
  252.                        
  253.                                 case "leap":
  254.                        
  255.                                     if (this.active)
  256.                                         return "...";
  257.                                     return "";
  258.                        
  259.                                 case 'fill':
  260.                        
  261.                                     if (this.active)
  262.                                         return " - ";
  263.                                     return "";
  264.                                 }
  265.                             }
  266.                         });
  267.                     }
  268.                     else {
  269.                        
  270.                         $html = 'No statistics information yet exists.';
  271.                         $('#dash_stats_ajax_div').html($html);
  272.                     }
  273.                 });
  274.             }
  275.             // Else we are clicking to hide history
  276.             else {
  277.                
  278.                 // Change button text
  279.                 $(this).text('Show History');
  280.                
  281.                 // Hide export buttons
  282.                 $('#export_stats_current_page').hide();
  283.                 $('#export_stats_entire_history').hide();
  284.                
  285.                 // Hide pagination div and pagination date div
  286.                 $('.pagination_dash').hide();
  287.                 $('#pagination_date').hide();
  288.                 $('#pagination_date_dropdown').hide();
  289.                
  290.                 // Adjust stats back to original values
  291.                 $('#company_type_owner').html($cur_market_comp_owners);
  292.                 $('#company_type_research_owner').html($cur_market_comp_res_owners);
  293.                 $('#company_type_research_data').html($cur_market_comp_res_data);
  294.                 $('#issue_e').html($cur_issues_cov_environmental);
  295.                 $('#issue_s').html($cur_issues_cov_social);
  296.                 $('#issue_g').html($cur_issues_cov_governance);
  297.                 $('#issue_esg').html($cur_issues_cov_combined);
  298.                 $('#pa_investors').html($cur_primary_aud_investors);
  299.                 $('#pa_consumers').html($cur_primary_aud_consumers);
  300.                 $('#pa_companies').html($cur_primary_aud_companies);
  301.                 $('#pt_rating').html($cur_product_type_rating);
  302.                 $('#pt_ranking').html($cur_product_type_ranking);
  303.                 $('#pt_index').html($cur_product_type_index);
  304.                
  305.                 // Adjust class name
  306.                 $('.dash_stats').removeClass('dash_stats_active');
  307.             }
  308.         });
  309.        
  310.         // Select dash stats date click function
  311.         $(document).on('change', '#select_dash_stats_date', function(e) {
  312.            
  313.             $page_dash = parseInt($(this).val(), 10) + 1;
  314.             paging_dash.setPage($page_dash);
  315.         });
  316.        
  317.         // *****************************************************************************
  318.         // Users Tab
  319.         // *****************************************************************************
  320.        
  321.         // Set sortable admin users table
  322.         $("table#gisr_admin_users").tablesorter({headers: { 0: { filter: false, sorter: false} }, widthFixed: true, widgets: ['filter'], widgetOptions: {
  323.             filter_defaultFilter: { 1: '~{query}' },
  324.             filter_columnFilters: true,
  325.             filter_placeholder: { search: 'Search...' },
  326.             filter_saveFilters: true,
  327.             filter_reset: '.reset'
  328.         }});
  329.        
  330.         // Filter results on search keyup
  331.         $('#filter_user_table').keyup(function() {
  332.            
  333.             search_text = $(this).val();
  334.            
  335.             // Fire ajax to approve company
  336.             $.post("<?php echo base_url() . index_page(); ?>admin/filter_users", {search_text: search_text}).done(function(data) {
  337.                
  338.                 // Clear table results
  339.                 $('table#gisr_admin_users tbody').html('');
  340.                
  341.                 // Set returned html
  342.                 html = '';
  343.                
  344.                 // If results are returned
  345.                 if(data) {
  346.                    
  347.                     // Loop each returned array
  348.                     $.each(data, function(i, v) {
  349.                        
  350.                         // Add to returned html
  351.                         html += '<tr><td><input type="checkbox" name="select_edit_users[]" value="' + v.user_id + '" /></td><td>' + v.first_name + ' ' + v.last_name + '</td><td>' + v.email + '</td><td>' + v.user_level + '</td></tr>';
  352.                     });
  353.                 }
  354.                
  355.                 // Append html to tbody
  356.                 $('table#gisr_admin_users tbody').append(html);
  357.                        
  358.                 // let tablesorter know we made an update
  359.                 $("table#gisr_admin_users").trigger("update");
  360.                
  361.                 // Set sorting column and direction, this will sort on the first and third column
  362.                 sorting = [[0,0]];
  363.                
  364.                 // Sort on the first column
  365.                 $("table#gisr_admin_users").trigger("sorton", [sorting]);
  366.             });
  367.         });
  368.        
  369.         // Show other text fields
  370.         if($('.stakeholder_group').val() === 'other') {
  371.             $('#stakeholder_group_hidden_tr').show();
  372.         }
  373.         $('.stakeholder_group').change(function() {
  374.            
  375.             $val = $(this).val();
  376.             if($val === 'other') {
  377.                 $('#stakeholder_group_hidden_tr').show();
  378.             }
  379.             else {
  380.                 $('#stakeholder_group_hidden_tr').hide();
  381.             }
  382.         });
  383.        
  384.         if($('.job_function').val() === 'other') {
  385.             $('#job_function_hidden_tr').show();
  386.         }
  387.         $('.job_function').change(function() {
  388.            
  389.             $val = $(this).val();
  390.             if($val === 'other') {
  391.                 $('#job_function_hidden_tr').show();
  392.             }
  393.             else {
  394.                 $('#job_function_hidden_tr').hide();
  395.             }
  396.         });
  397.        
  398.         // Submit button for create user
  399.         $('#submit_create_user_profile').click(function(e) {
  400.            
  401.             // Ensure these form fields contain values
  402.             first_name = $('.first_name').val();
  403.             last_name = $('.last_name').val();
  404.             comp_name = $('.comp_name').val();
  405.             assigned_comp = $('.assigned_comp').val();
  406.             job_title = $('.job_title').val();
  407.             email = $('.email').val();
  408.             zip_code = $('.zip_code').val();
  409.             country = $('.country').val();
  410.             stakeholder_group = $('.stakeholder_group').val();
  411.             job_function = $('.job_function').val();
  412.             password = $('.password').val();
  413.             user_status = $('.user_status').val();
  414.             gisr_admin = $('.gisr_admin').val();
  415.             owner = $('.owner').val();
  416.             res_org = $('.res_org').val();
  417.             core_s = $('.core_s').val();
  418.             registered = $('.registered').val();
  419.             user_level = $('.user_level').val();
  420.             approved = $('.approved').val();
  421.             created_on = $('.created_on').val();
  422.            
  423.             if (first_name == '' || last_name == '' || comp_name == '' || assigned_comp == '' || job_title == '' || email == '' || zip_code == '' || country == '' || stakeholder_group == '' || job_function == '' || password == '' || user_status == '' || gisr_admin == '' || owner == '' || res_org == '' || core_s == '' || registered == '' || user_level == '' || approved == '' || created_on == '') {
  424.                
  425.                 e.preventDefault();
  426.                 $.alert({
  427.                     title: 'Fields Not Completed',
  428.                     content: 'All fields are required to create a user.',
  429.                     columnClass: 'col-md-4 col-md-offset-4',
  430.                     confirmButtonClass: 'btn-danger'
  431.                 });
  432.             }
  433.         });
  434.        
  435.         // Submit button for edit user
  436.         $('#submit_edit_user').click(function(e) {
  437.        
  438.             // Get checkbox values (checked)
  439.             checkboxes = $('input:checkbox:checked');
  440.            
  441.             // If no checkboxes are checked
  442.             if(checkboxes.length == 0) {
  443.                
  444.                 e.preventDefault();
  445.                 $.alert({
  446.                     title: 'Select User',
  447.                     content: 'Please select a user to edit.',
  448.                     columnClass: 'col-md-4 col-md-offset-4',
  449.                     confirmButtonClass: 'btn-info'
  450.                 });
  451.             }
  452.            
  453.             if(checkboxes.length > 1) {
  454.                
  455.                 e.preventDefault();
  456.                 $.alert({
  457.                     title: 'Only One User',
  458.                     content: 'Only one user may be edited at a time.',
  459.                     columnClass: 'col-md-4 col-md-offset-4',
  460.                     confirmButtonClass: 'btn-info'
  461.                 });
  462.             }
  463.         });
  464.        
  465.         // Submit button for delete user
  466.         $('#submit_delete_user').click(function(e) {
  467.            
  468.             e.preventDefault();
  469.        
  470.             // Get checkbox values (checked)
  471.             checkboxes = $('input:checkbox:checked');
  472.            
  473.             // If no checkboxes are checked
  474.             if(checkboxes.length == 0) {
  475.                
  476.                 $.alert({
  477.                     title: 'Delete User(s)',
  478.                     content: 'Please select a user(s) to delete.',
  479.                     columnClass: 'col-md-4 col-md-offset-4',
  480.                     confirmButtonClass: 'btn-info'
  481.                 });
  482.             }
  483.             else {
  484.                
  485.                 $.confirm({
  486.                     title: 'Delete User(s)',
  487.                     content: 'A user(s) is about to be deleted. Continue?',
  488.                     columnClass: 'col-md-4 col-md-offset-4',
  489.                     confirmButtonClass: 'btn-info',
  490.                     cancelButtonClass: 'btn-danger',
  491.                     confirm: function(){
  492.                         $('#submit_delete_user_confirmed').click();
  493.                     }
  494.                 });
  495.             }
  496.         });
  497.        
  498.         // Users tab submit view awaiting_approval user form
  499.         $('.view_user').click(function() {
  500.            
  501.             // Get comp id
  502.             user_id = $(this).attr('id');
  503.            
  504.             // Open new window with loaded company form
  505.             window.location.href = '<?php echo base_url().index_page(); ?>admin/admin_user/manage_user/edit_user/'+user_id;
  506.         });
  507.        
  508.         // Users tab submit approve user
  509.         $('.approve_user').click(function() {
  510.            
  511.             var $this = $(this);
  512.            
  513.             // Confirm approve user
  514.             $.confirm({
  515.                 title: 'Approve User?',
  516.                 content: 'Please confirm approval of this user.',
  517.                 columnClass: 'col-md-4 col-md-offset-4',
  518.                 confirmButtonClass: 'btn-info',
  519.                 cancelButtonClass: 'btn-danger',
  520.                 cancelButton: 'Cancel',
  521.                 confirm: function(){
  522.            
  523.                     // Get user id
  524.                     user_id = $($this).attr('id');
  525.                    
  526.                     // Fire ajax to approve company
  527.                     $.post("<?php echo base_url() . index_page(); ?>admin/approve_user", {user_id: user_id}).done(function(data) {
  528.                        
  529.                         if(data.update_message == 'fail') {
  530.                            
  531.                             $.alert({
  532.                                 title: 'User Approval Failed.',
  533.                                 content: 'This user approval failed. Please contact a system administrator.',
  534.                                 columnClass: 'col-md-4 col-md-offset-4',
  535.                                 confirmButtonClass: 'btn-info'
  536.                             });
  537.                            
  538.                             return;
  539.                         }
  540.                         else if(data.update_message == 'success') {
  541.                            
  542.                             $.alert({
  543.                                 title: 'User Approval Successful.',
  544.                                 content: 'This user was approved successfully.',
  545.                                 columnClass: 'col-md-4 col-md-offset-4',
  546.                                 confirmButtonClass: 'btn-info',
  547.                                 confirm: function() {
  548.                                    
  549.                                     window.location.reload(false);
  550.                                 }
  551.                             });
  552.                         }
  553.                     });
  554.                 }
  555.             });
  556.         });
  557.        
  558.        
  559.         // *****************************************************************************
  560.         // Companies Tab
  561.         // *****************************************************************************
  562.        
  563.         // Companies tab step 1
  564.         $('#companies_tab_select_comp').on('change', function() {
  565.            
  566.             $('#companies_tab_buttons').show();
  567.         });
  568.        
  569.         // Companies tab deactivate company
  570.         $('#companies_tab_submit_deactivate').click(function() {
  571.            
  572.             $.confirm({
  573.                 title: 'Deactivate Company?',
  574.                 content: 'Please enter a reason why this company is being deactivated.<br><br><textarea id="reason_rejected_text" style="width:100%;"></textarea><br><br><strong>Note: </strong>All products associated with this company will also be deactivated.',
  575.                 columnClass: 'col-md-4 col-md-offset-4',
  576.                 confirmButtonClass: 'btn-info',
  577.                 cancelButtonClass: 'btn-danger',
  578.                 confirm: function(){
  579.                    
  580.                     comp_id = $('#companies_tab_select_comp').val();
  581.                     reason_rejected = $(this.$b.find('#reason_rejected_text')).val();
  582.                    
  583.                     $.post("<?php echo base_url() . index_page(); ?>admin/deactivate_company", {comp_id: comp_id, reason_rejected: reason_rejected}).done(function(data) {
  584.                        
  585.                         if(data.update_message == 'fail') {
  586.                            
  587.                             $.alert({
  588.                                 title: 'Company Update Failed.',
  589.                                 content: 'This company update failed. Please contact a system administrator.',
  590.                                 columnClass: 'col-md-4 col-md-offset-4',
  591.                                 confirmButtonClass: 'btn-info'
  592.                             });
  593.                            
  594.                             return;
  595.                         }
  596.                         else if(data.update_message == 'success') {
  597.                            
  598.                             $.alert({
  599.                                 title: 'Company Update Successful.',
  600.                                 content: 'This company was deactivated successfully.',
  601.                                 columnClass: 'col-md-4 col-md-offset-4',
  602.                                 confirmButtonClass: 'btn-info',
  603.                                 confirm: function() {
  604.                                    
  605.                                     window.location.reload(false);
  606.                                 }
  607.                             });
  608.                         }
  609.                     });
  610.                 }
  611.             });
  612.         });
  613.        
  614.         // Companies tab submit view awaiting_approval company form
  615.         $('.view_company').click(function() {
  616.            
  617.             // Get comp id
  618.             comp_id = $(this).attr('id');
  619.            
  620.             // Open new window with loaded company form
  621.             window.location.href = '<?php echo base_url().index_page(); ?>survey/surveyform_edit_company/'+comp_id;
  622.         });
  623.        
  624.         // Companies tab submit approve company
  625.         $('.approve_company').click(function() {
  626.            
  627.             var $this = $(this);
  628.            
  629.             // Confirm approve company
  630.             $.confirm({
  631.                 title: 'Approve Company?',
  632.                 content: 'Please confirm approval of this company.',
  633.                 columnClass: 'col-md-4 col-md-offset-4',
  634.                 confirmButtonClass: 'btn-info',
  635.                 cancelButtonClass: 'btn-danger',
  636.                 confirm: function(){
  637.            
  638.                     // Get comp id
  639.                     comp_id = $($this).attr('id');
  640.                    
  641.                     // Fire ajax to approve company
  642.                     $.post("<?php echo base_url() . index_page(); ?>admin/approve_company", {comp_id: comp_id}).done(function(data) {
  643.                        
  644.                         if(data.revisions_exist == 'true') {
  645.                            
  646.                             $.alert({
  647.                                 title: 'Company Revisions Exist',
  648.                                 content: 'This company contains revisions. Please first complete any company revisions.',
  649.                                 columnClass: 'col-md-4 col-md-offset-4',
  650.                                 confirmButtonClass: 'btn-danger'
  651.                             });
  652.                            
  653.                             return;
  654.                         }
  655.                         else if(data.update_message == 'fail') {
  656.                            
  657.                             $.alert({
  658.                                 title: 'Company Approval Failed.',
  659.                                 content: 'This company approval failed. Please contact a system administrator.',
  660.                                 columnClass: 'col-md-4 col-md-offset-4',
  661.                                 confirmButtonClass: 'btn-danger'
  662.                             });
  663.                            
  664.                             return;
  665.                         }
  666.                         else if(data.update_message == 'success') {
  667.                            
  668.                             $.alert({
  669.                                 title: 'Company Approval Successful.',
  670.                                 content: 'This company was approved successfully.',
  671.                                 columnClass: 'col-md-4 col-md-offset-4',
  672.                                 confirmButtonClass: 'btn-info',
  673.                                 confirm: function() {
  674.                                    
  675.                                     window.location.reload(false);
  676.                                 }
  677.                             });
  678.                         }
  679.                     });
  680.                 }
  681.             });    
  682.         });
  683.        
  684.         // Companies tab submit reactivate company (deactivated comps)
  685.         $('.reactivate_company').click(function() {
  686.            
  687.             var $this = $(this);
  688.            
  689.             $.confirm({
  690.                 title: 'Reactivate Company?',
  691.                 content: 'This company is about to be reactivated. Should all associated products also be reactivated?<br><br>'+
  692.                             '<table><tbody style="display:block;">'+
  693.                             '<tr><td>Yes:</td><td><input type="radio" name="reactivate_prods_from_comp" value="yes" /></td></tr>'+
  694.                             '<tr><td>No:</td><td><input type="radio" name="reactivate_prods_from_comp" value="no" checked="checked" /></td></tr>'+
  695.                             '</tbody></table>',
  696.                 columnClass: 'col-md-4 col-md-offset-4',
  697.                 confirmButtonClass: 'btn-info',
  698.                 cancelButtonClass: 'btn-danger',
  699.                 confirm: function(){
  700.                    
  701.                     // Get form input name value
  702.                     load_prods = this.$b.find('input[name=reactivate_prods_from_comp]:checked').val();
  703.                    
  704.                     // Get comp id
  705.                     comp_id = $($this).attr('id');
  706.                    
  707.                     $.post("<?php echo base_url() . index_page(); ?>admin/reactivate_company", {comp_id: comp_id, load_prods: load_prods}).done(function(data) {
  708.                        
  709.                         if(data.update_message == 'fail') {
  710.                            
  711.                             $.alert({
  712.                                 title: 'Company Update Failed.',
  713.                                 content: 'This company update failed. Please contact a system administrator.',
  714.                                 columnClass: 'col-md-4 col-md-offset-4',
  715.                                 confirmButtonClass: 'btn-info'
  716.                             });
  717.                            
  718.                             return;
  719.                         }
  720.                         else if(data.update_message == 'success') {
  721.                            
  722.                             $.alert({
  723.                                 title: 'Company Reactivation Successful.',
  724.                                 content: 'This company was reactivated successfully.',
  725.                                 columnClass: 'col-md-4 col-md-offset-4',
  726.                                 confirmButtonClass: 'btn-info',
  727.                                 confirm: function() {
  728.                                    
  729.                                     window.location.reload(false);
  730.                                 }
  731.                             });
  732.                         }
  733.                     });
  734.                 }
  735.             });
  736.         });
  737.        
  738.        
  739.         // *****************************************************************************
  740.         // Products Tab
  741.         // *****************************************************************************
  742.        
  743.         // Products tab step 1 (load products from company)
  744.         $('#products_tab_select_comp').on('change', function() {
  745.            
  746.             // Clear any appended items in step 2
  747.             $('#product_tab_select_prod').html('');
  748.            
  749.             // Get company id from value
  750.             comp_id = $(this).val();
  751.            
  752.             // Post ajax to get associated products
  753.             $.post("<?php echo base_url() . index_page(); ?>admin/prod_tab_admin_prod_lookup", {comp_id: comp_id}).done(function(data) {
  754.                
  755.                 if(data.query !== false) {
  756.                
  757.                     html = '<option value="">Select...</option>';
  758.                        
  759.                     $.each(data, function(i, v) {
  760.                         $.each(v, function(ii, vv) {
  761.                            
  762.                             html += '<option value="'+vv.product_id+'">'+vv.product_name+'</option>';
  763.                         });
  764.                     });
  765.                    
  766.                     // Append select options to step 2
  767.                     $('#product_tab_select_prod').append(html);
  768.                 }
  769.                 else {
  770.                    
  771.                     $.alert({
  772.                         title: 'No Products',
  773.                         content: 'No products were found matching this company.',
  774.                         columnClass: 'col-md-4 col-md-offset-4',
  775.                         confirmButtonClass: 'btn-info'
  776.                     });
  777.                 }
  778.             });
  779.            
  780.             // Show step 2 dropdown
  781.             $('#products_tab_select_prod_div').show();
  782.            
  783.             // Hide action buttons
  784.             $('#products_tab_buttons').hide();
  785.         });
  786.        
  787.         // Products tab step 2 (load action button from product)
  788.         $('#product_tab_select_prod').on('change', function() {
  789.            
  790.             // Show action buttons
  791.             $('#products_tab_buttons').show();
  792.         });
  793.        
  794.        
  795.         // Products tab submit view awaiting_approval product form
  796.         $('.view_product').click(function() {
  797.            
  798.             // Get comp id / prod id
  799.             comp_id_prod_id = $(this).attr('id');
  800.            
  801.             // Open new window with loaded company form
  802.             window.location.href = '<?php echo base_url().index_page(); ?>survey/survey_form_edit_product/'+comp_id_prod_id;
  803.         });
  804.        
  805.         // Products tab submit approve product
  806.         $('.approve_product').click(function() {
  807.            
  808.             var $this = $(this);
  809.            
  810.             // Confirm approve product
  811.             $.confirm({
  812.                 title: 'Approve Product?',
  813.                 content: 'Please confirm approval of this product.',
  814.                 columnClass: 'col-md-4 col-md-offset-4',
  815.                 confirmButtonClass: 'btn-info',
  816.                 cancelButtonClass: 'btn-danger',
  817.                 confirm: function(){
  818.            
  819.                     // Get comp id / prod id
  820.                     comp_id_prod_id = $($this).attr('id');
  821.                    
  822.                     // Fire ajax to approve company
  823.                     $.post("<?php echo base_url() . index_page(); ?>admin/approve_product", {comp_id_prod_id: comp_id_prod_id}).done(function(data) {
  824.                        
  825.                         if(data.revisions_exist == 'true') {
  826.                            
  827.                             $.alert({
  828.                                 title: 'Product Revisions Exist',
  829.                                 content: 'This product contains revisions. Please first complete any product revisions.',
  830.                                 columnClass: 'col-md-4 col-md-offset-4',
  831.                                 confirmButtonClass: 'btn-danger'
  832.                             });
  833.                            
  834.                             return;
  835.                         }
  836.                         else if(data.update_message == 'fail') {
  837.                            
  838.                             $.alert({
  839.                                 title: 'Product Approval Failed.',
  840.                                 content: 'This product approval failed. Please contact a system administrator.',
  841.                                 columnClass: 'col-md-4 col-md-offset-4',
  842.                                 confirmButtonClass: 'btn-info'
  843.                             });
  844.                            
  845.                             return;
  846.                         }
  847.                         else if(data.update_message == 'success') {
  848.                            
  849.                             $.alert({
  850.                                 title: 'Product Approval Successful.',
  851.                                 content: 'This product was approved successfully.',
  852.                                 columnClass: 'col-md-4 col-md-offset-4',
  853.                                 confirmButtonClass: 'btn-info',
  854.                                 confirm: function() {
  855.                                    
  856.                                     window.location.reload(false);
  857.                                 }
  858.                             });
  859.                         }
  860.                     });
  861.                 }
  862.             });    
  863.         });
  864.        
  865.        
  866.         // Products tab submit deactivate product
  867.         $('#products_tab_submit_deactivate').click(function() {
  868.            
  869.             $.confirm({
  870.                 title: 'Deactivate Product?',
  871.                 content: 'This product is about to be deactivated.<br><br><textarea id="reason_rejected_text" style="width:100%;"></textarea>',
  872.                 columnClass: 'col-md-4 col-md-offset-4',
  873.                 confirmButtonClass: 'btn-info',
  874.                 cancelButtonClass: 'btn-danger',
  875.                 confirm: function(){
  876.                    
  877.                     comp_id = $('#products_tab_select_comp').val();
  878.                     prod_id = $('#product_tab_select_prod').val();
  879.                     reason_rejected = $(this.$b.find('#reason_rejected_text')).val();
  880.                    
  881.                     $.post("<?php echo base_url() . index_page(); ?>admin/deactivate_product", {comp_id: comp_id, prod_id: prod_id, reason_rejected: reason_rejected}).done(function(data) {
  882.                        
  883.                         if(data.update_message == 'fail') {
  884.                            
  885.                             $.alert({
  886.                                 title: 'Product Update Failed.',
  887.                                 content: 'This product update failed. Please contact a system administrator.',
  888.                                 columnClass: 'col-md-4 col-md-offset-4',
  889.                                 confirmButtonClass: 'btn-info'
  890.                             });
  891.                            
  892.                             return;
  893.                         }
  894.                         else if(data.update_message == 'success') {
  895.                            
  896.                             $.alert({
  897.                                 title: 'Product Update Successful.',
  898.                                 content: 'This product was deactivated successfully.',
  899.                                 columnClass: 'col-md-4 col-md-offset-4',
  900.                                 confirmButtonClass: 'btn-info',
  901.                                 confirm: function() {
  902.                                    
  903.                                     window.location.reload(false);
  904.                                 }
  905.                             });
  906.                         }
  907.                     });
  908.                 }
  909.             });
  910.         });
  911.        
  912.         // Products tab submit reactivate product
  913.         $('.reactivate_product').click(function() {
  914.            
  915.             var $this = $(this);
  916.            
  917.             $.confirm({
  918.                 title: 'Reactivate Product?',
  919.                 content: 'This product is about to be reactivated. Continue?',
  920.                 columnClass: 'col-md-4 col-md-offset-4',
  921.                 confirmButtonClass: 'btn-info',
  922.                 cancelButtonClass: 'btn-danger',
  923.                 confirm: function(){
  924.                    
  925.                     comp_id = $($this).val();
  926.                     prod_id = $($this).attr('id');
  927.                    
  928.                     $.post("<?php echo base_url() . index_page(); ?>admin/reactivate_product", {comp_id: comp_id, prod_id: prod_id}).done(function(data) {
  929.                        
  930.                         if(data.check_comp_status == 'inactive') {
  931.                            
  932.                             $.alert({
  933.                                 title: 'Product Company Inactive',
  934.                                 content: 'This products company is inactive. Please first reactivate the company; then products can be reactivated.',
  935.                                 columnClass: 'col-md-4 col-md-offset-4',
  936.                                 confirmButtonClass: 'btn-danger'
  937.                             });
  938.                            
  939.                             return;
  940.                         }
  941.                        
  942.                         if(data.update_message == 'fail') {
  943.                            
  944.                             $.alert({
  945.                                 title: 'Product Update Failed.',
  946.                                 content: 'This product update failed. Please contact a system administrator.',
  947.                                 columnClass: 'col-md-4 col-md-offset-4',
  948.                                 confirmButtonClass: 'btn-info'
  949.                             });
  950.                            
  951.                             return;
  952.                         }
  953.                         else if(data.update_message == 'success') {
  954.                            
  955.                             $.alert({
  956.                                 title: 'Product Reactivation Successful.',
  957.                                 content: 'This product was reactivated successfully.',
  958.                                 columnClass: 'col-md-4 col-md-offset-4',
  959.                                 confirmButtonClass: 'btn-info',
  960.                                 confirm: function() {
  961.                                    
  962.                                     window.location.reload(false);
  963.                                 }
  964.                             });
  965.                         }
  966.                     });
  967.                 }
  968.             });
  969.         });
  970.        
  971.         // Products tab change product owner
  972.         $('#products_tab_submit_change_owner').click(function() {
  973.            
  974.             // Fire ajax to get all company names
  975.             $.post("<?php echo base_url() . index_page(); ?>admin/change_prod_owner_get_all_comps", {}).done(function(data) {
  976.            
  977.                 $select = '<select id="change_prod_owner_select"><option value="">Select...</option>';
  978.                
  979.                 $.each(data, function(i, v) {
  980.                    
  981.                     $select += '<option value="' + v.company_id + '">' + v.firm_name + '</option>';
  982.                 });
  983.            
  984.                 $select += '</select>';
  985.                 $select += '<br /><br />';
  986.                 $select += '<div id="change_prod_owner_prod_fam_div"></div>';
  987.                
  988.                 $.confirm({
  989.                     title: 'Change Product Owner',
  990.                     content: 'Select the new product owner:<br /><br />' + $select,
  991.                     columnClass: 'col-md-6 col-md-offset-3',
  992.                     confirmButtonClass: 'btn-info',
  993.                     cancelButtonClass: 'btn-danger',
  994.                     confirm: function(){
  995.                        
  996.                         // Get product id
  997.                         prod_id = $('#product_tab_select_prod').val();
  998.                         // Get new company id
  999.                         new_comp_id = this.$b.find('#change_prod_owner_select').val();
  1000.                         // Get new product family id
  1001.                         new_prod_fam_id = this.$b.find('#change_prod_owner_select_prod_fam').val();
  1002.                
  1003.                         // Check to ensure a new company is selected
  1004.                         if(comp_id == '') {
  1005.                            
  1006.                             $.alert({
  1007.                                 title: 'Select Company',
  1008.                                 content: 'Please select a new company to assign this product.',
  1009.                                 columnClass: 'col-md-4 col-md-offset-4',
  1010.                                 confirmButtonClass: 'btn-info'
  1011.                             });
  1012.                            
  1013.                             return false;
  1014.                         }
  1015.                        
  1016.                         // Check to ensure product family is selected
  1017.                         if(new_prod_fam_id == '') {
  1018.                            
  1019.                             $.alert({
  1020.                                 title: 'Select Product Family',
  1021.                                 content: 'Please select a product family for this product. One can be created in the Product Family tab if desired.',
  1022.                                 columnClass: 'col-md-4 col-md-offset-4',
  1023.                                 confirmButtonClass: 'btn-info'
  1024.                             });
  1025.                            
  1026.                             return false;
  1027.                         }
  1028.                        
  1029.                         $data = {prod_id: prod_id, new_comp_id: new_comp_id, new_prod_fam_id: new_prod_fam_id};
  1030.                        
  1031.                         // Fire ajax to change product owner
  1032.                         $.post("<?php echo base_url() . index_page(); ?>admin/change_prod_owner", $data).done(function(data) {
  1033.                            
  1034.                             if(data == 'success') {
  1035.                                
  1036.                                 $.alert({
  1037.                                     title: 'Change Successful',
  1038.                                     content: 'The product owner was changed successfully.',
  1039.                                     columnClass: 'col-md-4 col-md-offset-4',
  1040.                                     confirmButtonClass: 'btn-info',
  1041.                                     confirm: function() {
  1042.                                        
  1043.                                         // Reload page
  1044.                                         location.reload();
  1045.                                     }
  1046.                                 });
  1047.                             }
  1048.                             else {
  1049.                                
  1050.                                 $.alert({
  1051.                                     title: 'Error',
  1052.                                     content: 'An error was encountered while changing this product owner. Please contact a system administrator.',
  1053.                                     columnClass: 'col-md-4 col-md-offset-4',
  1054.                                     confirmButtonClass: 'btn-danger'
  1055.                                 });
  1056.                             }
  1057.                         });
  1058.                     }
  1059.                 })
  1060.             });
  1061.         });
  1062.         // Bind click event on change product owner company select
  1063.         $(document).on('change', '#change_prod_owner_select', function() {
  1064.            
  1065.             // Get this company id
  1066.             comp_id = $(this).val();
  1067.            
  1068.             // Fire ajax to get all product families associated with this company
  1069.             $.post("<?php echo base_url() . index_page(); ?>admin/change_prod_owner_get_new_comp_prod_fams", {comp_id: comp_id}).done(function(data) {
  1070.                
  1071.                 if(data) {
  1072.            
  1073.                     $select = '<select id="change_prod_owner_select_prod_fam"><option value="">Select...</option>';
  1074.                    
  1075.                     $.each(data, function(i, v) {
  1076.                        
  1077.                         $select += '<option value="' + v.product_family_id + '">' + v.family_name + '</option>';
  1078.                     });
  1079.                    
  1080.                     $select += '</select>';
  1081.                    
  1082.                    
  1083.                     $('#change_prod_owner_prod_fam_div').html('Select the new product family:<br /><br />' + $select);
  1084.                 }
  1085.                 else {
  1086.                    
  1087.                     $('#change_prod_owner_prod_fam_div').html('No product families found for this company. No problem, one can be created later.');
  1088.                 }
  1089.             });
  1090.         });
  1091.        
  1092.        
  1093.         // *****************************************************************************
  1094.         // Revisions Tab
  1095.         // *****************************************************************************
  1096.        
  1097.         // Revisions submit button
  1098.         $('#submit_admin_edits').click(function(e) {
  1099.            
  1100.             comp_select = $('#admin_select_company_edits').val();
  1101.             prod_select = $('#admin_select_product_edits').val();
  1102.            
  1103.             // Check if selects are empty
  1104.             if(comp_select === '' && prod_select === '') {
  1105.                
  1106.                 $.alert({
  1107.                     title: 'Select Company or Product',
  1108.                     content: 'Please select a company or product to edit.',
  1109.                     columnClass: 'col-md-4 col-md-offset-4',
  1110.                     confirmButtonClass: 'btn-info'
  1111.                 });
  1112.                
  1113.                 return;
  1114.             }
  1115.            
  1116.             // Check if both product and company are selected
  1117.             if(comp_select !== '' && prod_select !== '') {
  1118.                
  1119.                 $.alert({
  1120.                     title: 'Select Only One',
  1121.                     content: 'Only one company or product may be edited at a time.',
  1122.                     columnClass: 'col-md-4 col-md-offset-4',
  1123.                     confirmButtonClass: 'btn-info'
  1124.                 });
  1125.                
  1126.                 return;
  1127.             }
  1128.            
  1129.             // If editing a company
  1130.             if(comp_select !== '' && prod_select === '') {
  1131.                
  1132.                 // Redirect to edit form page
  1133.                 window.location.href = '<?php echo base_url() . index_page(); ?>survey/surveyform_edit_company/'+comp_select;
  1134.             }
  1135.            
  1136.             // If editing a product
  1137.             if(prod_select !== '' && comp_select === '') {
  1138.                
  1139.                 // Have to post to ajax to get company id for url build
  1140.                 $.post("<?php echo base_url() . index_page(); ?>admin/product_revisions", {prod_id: prod_select}).done(function(data) {
  1141.                    
  1142.                     if(data) {
  1143.                        
  1144.                         window.location.href = '<?php echo base_url() . index_page(); ?>survey/survey_form_edit_product/'+data.comp_id+'/'+prod_select;
  1145.                     }
  1146.                     else {
  1147.                         console.log('Error with Ajax.');
  1148.                     }
  1149.                 });
  1150.             }
  1151.         });
  1152.        
  1153.         // Revision history populate product select
  1154.         $('#admin_select_company_revision_history').on('change', function() {
  1155.            
  1156.             comp_id = $(this).val();
  1157.             $append = '';
  1158.            
  1159.             // Populate product dropdown select
  1160.             $.post("<?php echo base_url() . index_page(); ?>admin/populate_product_revision_history_select", {comp_id: comp_id})
  1161.                         .done(function (data) {
  1162.                            
  1163.                             $append += '<option value="">Select...</option>';
  1164.                            
  1165.                             $.each(data.revision_select_products, function(i, v) {
  1166.                                
  1167.                                 $append += '<option value="'+v.product_id+'">'+v.product_name+'</option>';
  1168.                             });
  1169.                            
  1170.                             $('#admin_select_product_revision_history').html('');
  1171.                             $('#admin_select_product_revision_history').append($append);
  1172.             });
  1173.            
  1174.             // Clear revision history html
  1175.             $('#revisions_ajax_div').html('');
  1176.                    
  1177.             // Clear pagination links
  1178.             $(".pagination").html('');
  1179.            
  1180.             // Clear date dropdown
  1181.             $('#revision_dates').html('');
  1182.            
  1183.             // Clear date title
  1184.             $('#date_changed_title').html('');
  1185.         });
  1186.        
  1187.         $('#admin_select_product_revision_history').on('change', function() {
  1188.            
  1189.             // Clear revision history html
  1190.             $('#revisions_ajax_div').html('');
  1191.                    
  1192.             // Clear pagination links
  1193.             $(".pagination").html('');
  1194.            
  1195.             // Clear date dropdown
  1196.             $('#revision_dates').html('');
  1197.            
  1198.             // Clear date title
  1199.             $('#date_changed_title').html('');
  1200.         });
  1201.        
  1202.         // Set vars for company and product "pretty names" objects
  1203.         var prod_array = {"product_id":"","company_id":"Company Id","research_company_id":"Research Company ID","product_name":"Product Name","product_type_rating":"Product Type (Rating)","product_type_ranking":"Product Type (Ranking)","product_type_index":"Product Type (Index)","primary_audience_companies":"Primary Audience (Companies)","primary_audience_investors":"Primary Audience (Investors)","primary_audience_consumers":"Primary Audience (Consumers)","primary_audience_other":"Primary Audience (Other)","primary_audience_other_text":"Primary Audience (Other) Text","product_description":"Product Description","product_url_information":"Product URL Information","prod_external_platform":"External Platform","total_number_of_company":"Total Number of Companies","selection_criteria":"Selection Criteria","rating_scale":"Rating Scale","underlying_universe":"Underlying Universe","market_coverage_large_cap":"Market Coverage (Large Cap)","market_coverage_mid_cap":"Market Coverage (Mid Cap)","market_coverage_small_cap":"Market Coverage (Small Cap)","market_coverage_privately_held":"Market Coverage (Privately Held)","geographic_coverage_global":"Geographic Coverage (Global)","geographic_coverage_asia":"Geographic Coverage (Asia)","geographic_coverage_europe":"Geographic Coverage (Europe)","geographic_coverage_latin_america":"Geographic Coverage (Latin America)","geographic_coverage_us":"Geographic Coverage (US)","geographic_coverage_emerging_market":"Geographic Coverage (Emerging Market)","geographic_coverage_other":"Geographic Coverage (Other)","geographic_coverage_other_text":"Geographic Coverage (Other) Text","category_coverage_esg_combined":"Category Coverage (ESG Combined)","category_coverage_environmental":"Category Coverage (Environmental)","category_coverage_social":"Category Coverage (Social)","category_coverage_governance":"Category Coverage (Governance)","category_coverage_incorporates_financial":"Category Coverage (Incorporates Financial)","total_number_of_esg_issues_covered":"Total Number of ESG Issues Covered","social_issues_same_as_in_section_3":"Social Issues (Same as in Section 3)","social_issues_2":"Social Issues (Page 2)","environmental_issues_same_as_in_section_3":"Environmental Issues (Same as in Section 3)","environmental_issues_2":"Environmental Issues (Page 2)","governance_issues_same_as_in_section_3":"Governance Issues (Same as in Section 3)","governance_issues_2":"Governance Issues (Page 2)","other_issues_same_as_in_section_3":"Other Issues (Same as in Section 3)","other_issues_2":"Other Issues (Page 2)","total_number_of_esg_indicators_covered":"Total Number of ESG Indicators Covered","product_environmental":"Environmental Indicators","product_social":"Social Indicators","product_governance":"Governance Indicators","product_other":"Other Indicators","methodological_basis_user_defined":"Methodological Basis (Customized\/User-defined )","methodological_basis_disclosure_based":"Methodological Basis (Disclosure-based)","methodological_basis_performance_based":"Methodological Basis (Performance-based)","methodological_basis_trends_based":"Methodological Basis (Trends-based)","methodological_basis_goals_based":"Methodological Basis (Goals-based\/normative)","methodological_basis_sustainability_context":"Methodological Basis (Sustainability Context)","methodological_basis_sector_based":"Methodological Basis (Sector-based Comparison)","methodology_update_frequency_annual":"Methodology Update Frequency (Annual)","methodology_update_frequency_bi_annual":"Methodology Update Frequency (Bi-Annual)","methodology_update_frequency_quarterly":"Methodology Update Frequency (Quarterly)","methodology_update_frequency_monthly":"Methodology Update Frequency (Monthly)","methodology_update_frequency_as_needed":"Methodology Update Frequency (As Needed)","methodology_update_frequency_other":"Methodology Update Frequency (Other)","methodology_update_frequency_other_text":"Methodology Update Frequency (Other) Text","methodological_method_analyst_based":"Methodological Method (Analyst-based)","methodological_method_model_based":"Methodological Method (Model-based)","methodological_method_hybrid":"Methodological Method (Hybrid)","data_sources_company_disclosure":"Data Sources (Company Disclosure)","data_sources_company_direct_contact":"Data Sources (Company Direct Contact)","data_sources_ngo_disclosure":"Data Sources (CSO\/NGO Disclosure)","data_sources_ngo_direct_contact":"Data Sources (CSO\/NGO Direct Contact)","data_sources_trade_union_direct_contact":"Data Sources (Trade Union Direct Contact)","data_sources_trade_union_disclosure":"Data Sources (Trade Union Disclosure)","data_sources_media":"Data Sources (Media)","data_sources_government":"Data Sources (Government)","data_sources_esg_data_provider":"Data Sources (ESG Data Provider)","data_sources_other":"Data Sources (Other)","data_sources_other_text":"Data Sources (Other) Text","data_gaps_exclude_company_for_missing_data":"Data Gaps (Exclude company for missing data)","data_gaps_assign_company_failing_score_for_missing_data":"Data Gaps (Assign company failing score for missing data)","data_gaps_penalize_company_for_missing_data":"Data Gaps (Penalize company for missing data)","data_gaps_not_counted":"Data Gaps (Not counted)","data_gaps_substitute_industry_average_data":"Data Gaps (Substitute industry average data)","data_gaps_substitute_model_driven_data":"Data Gaps (Substitute model-driven data)","data_gaps_not_applicable":"Data Gaps (Not applicable)","data_gaps_other":"Data Gaps (Other)","data_gaps_other_text":"Data Gaps (Other) Text","eval_update_freq_annual":"Evaluation Update Frequency (Annual)","eval_update_freq_annual_text":"Evaluation Update Frequency (Annual) Text","eval_update_freq_bi_annual":"Evaluation Update Frequency (Bi-Annual)","eval_update_freq_bi_annual_text":"Evaluation Update Frequency (Bi-Annual) Text","eval_update_freq_quarterly":"Evaluation Update Frequency (Quarterly)","eval_update_freq_monthly":"Evaluation Update Frequency (Monthly)","eval_update_freq_ongoing":"Evaluation Update Frequency (Ongoing)","eval_update_freq_incidents_exception":"Evaluation Update Frequency (Controversies\/incidents exception)","eval_update_freq_other":"Evaluation Update Frequency (Other)","eval_update_freq_other_text":"Evaluation Update Frequency (Other) Text","controversies_supersesed_update_cycle":"Controversies\/Incidents (Supersede Update Cycle)","controversies_alert_service":"Controversies\/Incidents (Alert Service)","controversies_next_update_cycle":"Controversies\/Incidents (Next Update Cycle)","controversies_not_included":"Controversies\/Incidents (Not Included)","client_disclosure_issue_complete_list":"Client Disclosure (Issues - Complete List)","client_disclosure_issue_partial_list":"Client Disclosure (Issues - Partial List)","client_disclosure_indicator_complete_list":"Client Disclosure (Indicators - Complete List)","client_disclosure_indicator_partial_list":"Client Disclosure (Indicators - Partial List)","client_disclosure_rating_methodology":"Client Disclosure (Ratings Methodology)","client_disclosure_rating_model":"Client Disclosure (Ratings Model)","client_disclosure_data_source":"Client Disclosure (Data Source)","public_disclosure_issue_complete_list":"Public Disclosure (Issues - Complete List)","public_disclosure_issue_partial_list":"Public Disclosure (Issues - Partial List)","public_disclosure_indicators_complete_list":"Public Disclosure (Indicators - Complete List)","public_disclosure_indicators_partial_list":"Public Disclosure (Indicators - Partial List)","public_disclosure_ratings_methodology":"Public Disclosure (Ratings Methodology)","public_disclosure_ratings_model":"Public Disclosure (Ratings Model)","public_disclosure_sector_benchmarking_Report":"Public Disclosure (Sector Benchmarking Report)","public_disclosure_ratings_summary_with_company_eval":"Public Disclosure (Sector Benchmarking Report (with company evalution))","public_disclosure_data_source":"Public Disclosure (Data Source)","public_disclosure_profile_rating":"Public Disclosure (Profile\/Rating)","comp_disclosure_issue_complete_list_fee":"Related Company Disclosure (Issues - Complete List for a fee)","comp_disclosure_issue_complete_list_no_charge":"Related Company Disclosure (Issues - Complete List at no charge)","comp_disclosure_issue_partial_list_for_a_fee":"Related Company Disclosure (Issues - Partial List for a fee)","comp_disclosure_issue_partial_list_no_charge":"Related Company Disclosure (Issues - Partial List at no charge)","comp_disclosure_indicators_complete_list_for_a_fee":"Related Company Disclosure (Indicators - Complete List for a fee)","comp_disclosure_indicators_complete_list_no_charge":"Related Company Disclosure (Indicators - Complete List at no charge)","comp_disclosure_indicators_partial_list_for_a_fee":"Related Company Disclosure (Indicators - Partial List for a fee)","comp_disclosure_indicators_partial_list_no_charge":"Related Company Disclosure (Indicators - Partial List at no charge)","comp_disclosure_rating_methodology_for_a_fee":"Related Company Disclosure (Ratings Methodology for a fee)","comp_disclosure_rating_methodology_no_charge":"Related Company Disclosure (Ratings Methodology no charge)","comp_disclosure_rating_model_for_a_fee":"Related Company Disclosure (Ratings Model for a fee)","comp_disclosure_rating_model_no_charge":"Related Company Disclosure (Ratings Model at no charge)","comp_disclosure_data_source_no_charge":"Related Company Disclosure (Data Source for a fee)","comp_disclosure_data_source_for_a_fee":"Related Company Disclosure (Data Source at no charge)","comp_disclosure_individual_profile_rating_for_a_fee":"Related Company Disclosure (Individual Profile\/Rating for a fee)","comp_disclosure_individual_profile_Rating_at_no_charge":"Related Company Disclosure (Individual Profile\/Rating at no charge)","comp_disclosure_all_profile_rating_for_a_fee":"Related Company Disclosure (All Profiles\/Ratings for a fee)","comp_disclosure_all_profile_rating_at_no_charge":"Related Company Disclosure (All Profiles\/Ratings at no charge)","comp_disclosure_sector_bench_report_for_a_fee":"Related Company Disclosure (Sector Benchmarking Report for a fee)","comp_disclosure_sector_bench_report_at_no_charge":"Related Company Disclosure (Sector Benchmarking Report at no charge)","comp_disclosure_sector_bench_report_comp_evalua_for_a_fee":"Related Company Disclosure (Sector Benchmarking Report (with company evaluations) for a fee)","comp_disclosure_sector_bench_report_comp_evalua_at_no_charge":"Related Company Disclosure (Sector Benchmarking Report (with company evaluations) at no charge)","comp_disclosure_other":"Related Company Disclosure (Other)","comp_disclosure_other_text":"Related Company Disclosure (Other) Text","rated_comp_inter_responds_to_requests_for_assist_on_survey":"Rated Company Interaction (Rater responds to requests for assistance on survey\/questionnaire)","rated_comp_inter_offers_opport_to_review_on_rating":"Rated Company Interaction (Rater offers opportunity to review and comment on rating\/profile)","rated_comp_inter_assist_on_survey_before_finalized":"Rated Company Interaction (Rater offers opportunity to review and comment on rating\/profile before its finalized)","rated_comp_inter_has_protocol_to_address_grievances":"Rated Company Interaction (Rater has protocol\/policy to address errors or grievances)","rated_comp_inter_provide_url_brief_description":"Rated Company Interaction (Rater has protocol\/policy to address errors or grievances URL)","rated_comp_inter_rater_provides_free_feedback_to_improve_scorer":"Rated Company Interaction (Rater provides free feedback to improve\/enhance score and performance)","rated_comp_inter_rater_offers_advisory_services_for_a_fee":"Rated Company Interaction (Rater offers advisory services for a fee)","rated_comp_inter_rater_no_interaction":"Rated Company Interaction (No interaction)","rated_comp_inter_rater_other":"Rated Company Interaction (Other)","rated_comp_inter_rater_other_text":"Rated Company Interaction (Other) Text","survey_use_yes":"Survey Use (Yes)","survey_use_no":"Survey Use (No)","survey_cycle":"Survey Cycle","survey_cycle_date":"Survey Cycle Date","response_times":"Response Times","product_source_notes":"Source Notes (Page 1)","product_source_notes_2":"Source Notes (Page 2)","product_source_notes_3":"Source Notes (Page 3)","product_source_notes_4":"Source Notes (Page 4)","gisr_reviewed_product_yes":"GISR Reviewed (Yes)","gisr_reviewed_product_no":"GISR Reveiwed (No)","product_comments_question":"Comments\/Questions","owner_reviewed_product_yes":"Owner Reviewed (Yes)","owner_reviewed_product_no":"Owner Reviewed (No)","profile_complete_product_yes":"Profile Complete (Yes)","profile_complete_product_no":"Profile Complete (No)","prod_research_organization":"Research Organization","prod_add_res_providers":"Additional Research Providers","prod_company_name":"Company name","prod_date_completed":"Date Completed","prod_contact_info":"Contact Info","prod_added_by":"Added By","prod_edits_approved":"Edits Approved","prod_status":"Status","prod_status_reason":"Status Reason"};
  1204.        
  1205.         var comp_array = {"company_id":"Company ID","firm_name":"Firm Name","firm_logo":"Firm Logo","website":"Website","email_invest":"Email (Investors)","email_rated":"Email (Rated Company)","email_general":"Email (General)","headquarters":"Headquarters","phone_no":"Phone Number","agency_description":"Agency Description","esg_audience_companies":"ESG Audience (Companies)","esg_audience_investors":"ESG Audience (Investors)","esg_audience_consumers":"ESG Audience (Consumers)","esg_audience_government":"ESG Audience (Government)","esg_audience_other":"ESG Audience (Other)","esg_audience_other_text":"ESG Audience (Other) Text","coverage_environmental":"Coverage (Environmental)","coverage_social":"Coverage (Social)","coverage_governance":"Coverage (Governance)","coverage_other":"Coverage (Other)","coverage_other_text":"Coverage (Other) Text","esg_prod_ser_analytics":"ESG Products\/Services (Analytics)","esg_prod_ser_bespoke_research":"ESG Products\/Services (Bespoke Research)","esg_prod_ser_company_profiles_research":"ESG Products\/Services (Company Profiles\/Research )","esg_prod_ser_company_rankings":"ESG Products\/Services (Company Rankings)","esg_prod_ser_company_ratings":"ESG Products\/Services (Company Ratings)","esg_prod_ser_controversies_incidents_monitoring_alerts":"ESG Products\/Services (Controversies\/Incidents Monitoring & Alerts)","esg_prod_ser_country_analysis":"ESG Products\/Services (Country Analysis)","esg_prod_ser_corporate_engagement":"ESG Products\/Services (Corporate Engagement)","esg_prod_ser_datafeeds":"ESG Products\/Services (Datafeeds)","esg_prod_ser_dr_cr_fixed_income_esg_research_and_or_ratings":"ESG Products\/Services (Other Debit\/Credit - Fixed Income ESG Research and\/or Ratings)","esg_prod_ser_green_bonds":"ESG Products\/Services (Green Bonds)","esg_prod_ser_indices":"ESG Products\/Services (Indices)","esg_prod_ser_portfolio_analysis":"ESG Products\/Services (Portfolio Analysis)","esg_prod_ser_proxy_voting_research":"ESG Products\/Services (Proxy Voting Research)","esg_prod_ser_screening_restriction_management_services":"ESG Products\/Services (Screening\/Restriction Management Services)","esg_prod_ser_raw_data":"ESG Products\/Services (Raw Data)","distinguishing_characteristics":"Distinguishing Characteristics","aum_utilizing_agency_esg_prod_ser_less_than_1_million":"AUM Utilizing Agencys ESG Products\/Services (< $1 million)","aum_utilizing_agency_esg_prod_ser_bw_1_million_250_million":"AUM Utilizing Agencys ESG Products\/Services ($1 - $250 million)","aum_utilizing_agency_esg_prod_ser_bw_250_million_500_million":"AUM Utilizing Agencys ESG Products\/Services ($250 - 500 million)","aum_utilizing_agency_esg_prod_ser_greater_than_500_million":"AUM Utilizing Agencys ESG Products\/Services (> $500 million)","aum_utilizing_agency_esg_prod_ser_other":"AUM Utilizing Agencys ESG Products\/Services (Other)","date_founded":"Date Founded","key_milestones":"Key Milestones","ownership_structure":"Ownership Structure","business_partnerships":"Business Partnerships","academic_partnerships":"Academic Partnerships","significant_interests_in_other_companies":"Significant Interests in Other Companies","regional_offices":"Regional Offices","total_number_emp_fte":"Total Number of Employees (FTE)","directly_employed_permanent_fte":"(FTE) Directly Employed Permanently","total_number_emp_fte_esg_research_and_rating":"Total Number of Employees Research and Rating (FTERR)","directly_employed_permanent_fte_esg_research_and_rating":"(FTERR) Directly Employed Permanently","total_number_emp_fte_esg_research_analysts":"Total Number of Employees (FTERA)","directly_employed_permanent_fte_esg_research_analysts":"(FTERA) Directly Employed Permanently","additional_ESG_Products_Services_not_inc_at_a_glance":"Additional ESG Products\/Services not included in \"At A Glance\"","quality_assurance_arista_certified":"Quality Assurance (ARISTA Certified)","quality_assurance_iso":"Quality Assurance (ISO)","quality_assurance_other_third_party":"Quality Assurance (Other\/Third Party)","quality_assurance_other_third_party_text":"Quality Assurance (Other\/Third Party) Text","annual_reports_yes":"Annual Reports (Yes)","annual_reports_yes_text":"Annual Reports (Yes) Text","annual_reports_no":"Annual Reprts (No)","sustainability_report_yes":"Sustainability Reports (Yes)","sustainability_report_yes_text":"Sustainability Reports (Yes) Text","sustainability_report_no":"Sustainablility Reports (No)","code_of_conduct_yes":"Code of Conduct (Yes)","code_of_conduct_yes_text":"Code of Conduct (Yes) Text","code_of_conduct_no":"Code of Conduct (No)","Independence_policy_yes":"Indepedence Policy (Yes)","Independence_policy_yes_text":"Independence Policy (Yes) Text","Independence_policy_no":"Independence Policy (No)","materiality_single":"Materiality (Yes)","materiality_single_text":"Materiality (Yes) Text","materiality_multiple":"Materiality (No)","environmental_issue":"Environmental Issue","social_issue":"Social Issue","governance_issue":"Governance Issue","other_issue":"Other Issue","aum_utilizing_agency_esg_prod_ser_other_text":"AUM Utilizing Agencys ESG Products\/Services (Other) TEXT","added_by":"Added By","contact_info":"Contact Info","date_completed":"Date Completed","aum_utilizing_agency_esg_prod_ser_unknown":"","membership_pri":"Membership (PRI)","membership_arise":"Membership (ARISE)","membership_other":"Membership (Other)","membership_other_text":"Membership (Other) Text","quality_assurance_arista_certified_text":"Quality Assurance (ARISTA Certified) Text","quality_assurance_iso_text":"Quality Assurance (ISO) Text","annual_reports_publicly_available":"Annual Reports (Publicly Available)","sustainability_report_publicly_available":"Sustainability Reports (Publicly Available)","code_of_conduct_publicly_available":"Code of Conduct (Publicly Available)","Independence_policy_publicly_available":"Independence Policy (Publicly Available)","company_source_notes":"Company Source Notes","company_source_notes_2":"Company Source Notes (Page 2)","company_source_notes_3":"Company Source Notes (Page 3)","company_source_notes_4":"Company Source Notes (Page 4)","profile_compelete_yes":"Profile Complete (Yes)","profile_compelete_no":"Profile Complete (No)","owner_reviewed_yes":"Owner Reviewed (Yes)","owner_reviewed_no":"Owner Reviewed (No)","gisr_reviewed_yes":"GISR Reviewed (Yes)","gisr_reviewed_no":"GISR Reviewed (No)","comments_question":"Comments\/Questions","additional_esg_product_service":"Additional ESG Product\/Service","quality_assurance_company_profile":"Quality Assurance Company Profile","quality_assurance_company_profile_url":"Quality Assurance Company Profile URL","additional_esg_product_service_url":"Additional ESG Product\/Service URL","edits_approved":"Edits Approved","status":"Status","company_type":"Company Type","status_reason":"Status Reason"};
  1206.        
  1207.        
  1208.         // Load entire revision history
  1209.         $('#submit_admin_load_entire_revisions').click(function() {
  1210.            
  1211.             comp_id = $('#admin_select_company_revision_history').val();
  1212.             prod_id = $('#admin_select_product_revision_history').val();
  1213.            
  1214.             // Check if selects are empty
  1215.             if(comp_id === '' && prod_id === '') {
  1216.                
  1217.                 $.alert({
  1218.                     title: 'Select Company or Product',
  1219.                     content: 'Please select a company or product to display revisions.',
  1220.                     columnClass: 'col-md-4 col-md-offset-4',
  1221.                     confirmButtonClass: 'btn-info'
  1222.                 });
  1223.                
  1224.                 return;
  1225.             }
  1226.            
  1227.             // Fire ajax to get company/product revision history
  1228.             $.post("<?php echo base_url() . index_page(); ?>admin/get_entire_revision_history/"+comp_id+'/'+prod_id)
  1229.             .done(function (data) {
  1230.                
  1231.                 // Reset page data
  1232.                 $('#revisions_ajax_div').html('');
  1233.                 $return = '';
  1234.                    
  1235.                 // Clear pagination links
  1236.                 $(".pagination").html('');
  1237.                
  1238.                 // Clear date dropdown
  1239.                 $('#revision_dates').html('');
  1240.                
  1241.                 // Clear date title
  1242.                 $('#date_changed_title').html('');
  1243.                                
  1244.                 // Create placeholders
  1245.                 $revision_id = '';
  1246.                 $changed_by = '';
  1247.                 $date_changed = '';
  1248.                 $date_drop_array = [];
  1249.                 $prod_or_comp = '';
  1250.                 $prod_comp_id = '';
  1251.                 $db_field_col_name = '';
  1252.                 $old_value = '';
  1253.                 $new_value = '';
  1254.                 $approved = '';
  1255.                 $reason_rejected = '';
  1256.                
  1257.                 // If there are results to paginate
  1258.                 if(data.company_product_revision_history) {
  1259.                    
  1260.                     $.each(data.company_product_revision_history, function (i, v) {
  1261.                                        
  1262.                         $return += '<div class="revision_history_item">';
  1263.                        
  1264.                             $.each(v, function(ii, vv) {
  1265.                                
  1266.                                 if(ii == 'revision_id') { $revision_id = vv; }
  1267.                                 if(ii == 'changed_by') { $changed_by = vv; }
  1268.                                 if(ii == 'moderated_by') { $moderated_by = vv; }
  1269.                                 if(ii == 'date_changed') { $date_changed = vv; }
  1270.                                 if(ii == 'prod_or_comp') { $prod_or_comp = vv; }
  1271.                                 if(ii == 'prod_comp_id') { $prod_comp_id = vv; }
  1272.                                 if(ii == 'db_field_col_name') {
  1273.                                
  1274.                                     // If this value is in the company array
  1275.                                     if (vv in comp_array) { $db_field_col_name = comp_array[vv]; }
  1276.                                     // Else if this value is in the product array
  1277.                                     else if (vv in prod_array) { $db_field_col_name = prod_array[vv]; }
  1278.                                     // Else use default value
  1279.                                     else $db_field_col_name = vv;
  1280.                                 }
  1281.                                 if(ii == 'old_value') {
  1282.                                     if(vv == 'Y') $old_value = 'Yes';
  1283.                                     else if(vv == 'N') $old_value = 'No';
  1284.                                     else $old_value = vv;
  1285.                                 }
  1286.                                 if(ii == 'new_value') {
  1287.                                     if(vv == 'Y') $new_value = 'Yes';
  1288.                                     else if(vv == 'N') $new_value = 'No';
  1289.                                     else $new_value = vv;
  1290.                                 }
  1291.                                 if(ii == 'approved') {
  1292.                                     if(vv == 'rejected') vv = 'Rejected';
  1293.                                     if(vv == 'Y') vv = 'Approved';
  1294.                                     $approved = vv;
  1295.                                 }
  1296.                                 if(ii == 'reason_rejected') { $reason_rejected = vv; }
  1297.                             });
  1298.                        
  1299.                             // Build each revision box
  1300.                             $return += '<div style="width:65%;float:left;">';
  1301.                                 $return += '<div class="revision_db_field_name"><strong>Form Field:</strong> ' + $db_field_col_name + '</div>';
  1302.                                 $return += '<div class="revision_approved"><strong>Status:</strong> ' + $approved + '</div>';
  1303.                             $return += '</div>';
  1304.                            
  1305.                             $return += '<div style="width:33%;float:right;">';
  1306.                                 $return += '<div class="revision_changed_by"><strong>Changed By:</strong> ' + $changed_by + '</div>';
  1307.                                 $return += '<div class="revision_changed_by"><strong>Moderated By:</strong> ' + $moderated_by + '</div>';
  1308.                                 $return += '<div class="revision_changed_by"><strong>Date Changed:</strong> ' + $date_changed + '</div>';
  1309.                             $return += '</div>';
  1310.                            
  1311.                             $return += '<div style="clear:both;"></div>';
  1312.                             $return += '<br />';
  1313.                            
  1314.                             $return += '<div class="revision_old_value"><strong>Old Value:</strong> ' + $old_value + '</div>';
  1315.                             $return += '<br />';
  1316.                             $return += '<div class="revision_new_value"><strong>New Value:</strong> ' + $new_value + '</div>';
  1317.                            
  1318.                             $return += '<br>';
  1319.                            
  1320.                             if($reason_rejected !== '' && $reason_rejected !== null) {
  1321.                                 $return += '<div class="revision_reason_rejected"><strong>Reason Rejected:</strong> ' + $reason_rejected + '</div>';
  1322.                             }
  1323.                            
  1324.                         $return += '</div>';
  1325.                     });
  1326.                    
  1327.                     // Populate ajax results div
  1328.                     $('#revisions_ajax_div').hide().html($return).fadeIn();
  1329.                 }
  1330.                 else {
  1331.                    
  1332.                     // Clear revision html
  1333.                     $html = 'There are no revisions for this item.';
  1334.                     $('#revisions_ajax_div').html($html);
  1335.                    
  1336.                     // Clear pagination links
  1337.                     $(".pagination").html('');
  1338.                    
  1339.                     // Clear date dropdown
  1340.                     $('#revision_dates').html('');
  1341.                    
  1342.                     // Clear date title
  1343.                     $('#date_changed_title').html('');
  1344.                 }
  1345.             });
  1346.         });
  1347.        
  1348.         // Load paginated date revision history
  1349.         $('#submit_admin_load_revisions').click(function() {
  1350.            
  1351.             comp_id = $('#admin_select_company_revision_history').val();
  1352.             prod_id = $('#admin_select_product_revision_history').val();
  1353.            
  1354.             // Check if selects are empty
  1355.             if(comp_id === '' && prod_id === '') {
  1356.                
  1357.                 $.alert({
  1358.                     title: 'Select Company or Product',
  1359.                     content: 'Please select a company or product to display revisions.',
  1360.                     columnClass: 'col-md-4 col-md-offset-4',
  1361.                     confirmButtonClass: 'btn-info'
  1362.                 });
  1363.                
  1364.                 return;
  1365.             }
  1366.            
  1367.             // Need to run ajax to get count needed for pagination
  1368.             $.post("<?php echo base_url() . index_page(); ?>admin/count_revision_pagination/"+comp_id+'/'+prod_id)
  1369.             .done(function (data) {
  1370.                
  1371.                 // Build date dropdown array variable
  1372.                 var $date_dropdown = [];
  1373.                 $.each(data.date_dropdown, function(i, v) {
  1374.                     $.each(v, function(ii, vv) {
  1375.                         if(ii === 'date_changed')
  1376.                             $date_dropdown.push(vv);
  1377.                     });
  1378.                 });
  1379.                
  1380.                 // If there are results to paginate
  1381.                 if(data.count !== 0) {
  1382.                    
  1383.                     // Paginate results
  1384.                     paging = $(".pagination").paging(data.count, {
  1385.                        
  1386.                         format: "[< - nncn - >]",
  1387.                         perpage: 1,
  1388.                         onSelect: function (page) {
  1389.                            
  1390.                             var $start = this.slice[0];
  1391.                             var $end = this.slice[1];
  1392.                            
  1393.                             data = {start: $start, end: $end};
  1394.                            
  1395.                             // Fire ajax to get company/product revision history
  1396.                             $.post("<?php echo base_url() . index_page(); ?>admin/get_revision_history/"+comp_id+'/'+prod_id, data)
  1397.                             .done(function (data) {
  1398.                                
  1399.                                 // Reset page data
  1400.                                 $('#revisions_ajax_div').html('');
  1401.                                 $return = '';
  1402.                                
  1403.                                 // Create placeholders
  1404.                                 $revision_id = '';
  1405.                                 $changed_by = '';
  1406.                                 $date_changed = '';
  1407.                                 $date_drop_array = [];
  1408.                                 $prod_or_comp = '';
  1409.                                 $prod_comp_id = '';
  1410.                                 $db_field_col_name = '';
  1411.                                 $old_value = '';
  1412.                                 $new_value = '';
  1413.                                 $approved = '';
  1414.                                 $reason_rejected = '';
  1415.                                
  1416.                                 $.each(data.company_product_revision_history, function (i, v) {
  1417.                                    
  1418.                                     $return += '<div class="revision_history_item">';
  1419.                                    
  1420.                                         $.each(v, function(ii, vv) {
  1421.                                            
  1422.                                             if(ii == 'revision_id') { $revision_id = vv; }
  1423.                                             if(ii == 'changed_by') { $changed_by = vv; }
  1424.                                             if(ii == 'date_changed') { $date_changed = vv;}
  1425.                                             if(ii == 'moderated_by') { $moderated_by = vv; }
  1426.                                             if(ii == 'prod_or_comp') { $prod_or_comp = vv; }
  1427.                                             if(ii == 'prod_comp_id') { $prod_comp_id = vv; }if(ii == 'db_field_col_name') {
  1428.                                                
  1429.                                                 // If this value is in the company array
  1430.                                                 if (vv in comp_array) { $db_field_col_name = comp_array[vv]; }
  1431.                                                 // Else if this value is in the product array
  1432.                                                 else if (vv in prod_array) { $db_field_col_name = prod_array[vv]; }
  1433.                                                 // Else use default value
  1434.                                                 else $db_field_col_name = vv;
  1435.                                             }
  1436.                                             if(ii == 'old_value') {
  1437.                                                 if(vv == 'Y') $old_value = 'Yes';
  1438.                                                 else if(vv == 'N') $old_value = 'No';
  1439.                                                 else $old_value = vv;
  1440.                                             }
  1441.                                             if(ii == 'new_value') {
  1442.                                                 if(vv == 'Y') $new_value = 'Yes';
  1443.                                                 else if(vv == 'N') $new_value = 'No';
  1444.                                                 else $new_value = vv;
  1445.                                             }
  1446.                                             if(ii == 'approved') {
  1447.                                                 if(vv == 'rejected') vv = 'Rejected';
  1448.                                                 if(vv == 'Y') vv = 'Approved';
  1449.                                                 $approved = vv;
  1450.                                             }
  1451.                                             if(ii == 'reason_rejected') { $reason_rejected = vv; }
  1452.                                         });
  1453.                                    
  1454.                                         // Build each revision box
  1455.                                         $return += '<div style="width:65%;float:left;">';
  1456.                                             $return += '<div class="revision_db_field_name"><strong>Form Field:</strong> ' + $db_field_col_name + '</div>';
  1457.                                             $return += '<div class="revision_approved"><strong>Status:</strong> ' + $approved + '</div>';
  1458.                                         $return += '</div>';
  1459.                                        
  1460.                                         $return += '<div style="width:33%;float:right;">';
  1461.                                             $return += '<div class="revision_changed_by"><strong>Changed By:</strong> ' + $changed_by + '</div>';
  1462.                                             $return += '<div class="revision_changed_by"><strong>Moderated By:</strong> ' + $moderated_by + '</div>';
  1463.                                         $return += '</div>';
  1464.                                        
  1465.                                         $return += '<div style="clear:both;"></div>';
  1466.                                         $return += '<br />';
  1467.                                        
  1468.                                         $return += '<div class="revision_old_value"><strong>Old Value:</strong> ' + $old_value + '</div>';
  1469.                                         $return += '<br />';
  1470.                                         $return += '<div class="revision_new_value"><strong>New Value:</strong> ' + $new_value + '</div>';
  1471.                                        
  1472.                                         $return += '<br>';
  1473.                                        
  1474.                                         if($reason_rejected !== '' && $reason_rejected !== null) {
  1475.                                             $return += '<div class="revision_reason_rejected"><strong>Reason Rejected:</strong> ' + $reason_rejected + '</div>';
  1476.                                         }
  1477.                                        
  1478.                                     $return += '</div>';
  1479.                                    
  1480.                                 });
  1481.                                
  1482.                                 // Populate ajax results div
  1483.                                 $('#revisions_ajax_div').hide().html($return).fadeIn();
  1484.                                
  1485.                                 // Populate date dropdown
  1486.                                 $date_drop = '<select name="select_revision_date" id="select_revision_date">';
  1487.                                 $date_drop += '<option value="">Select Date...</option>';
  1488.                                 $.each($date_dropdown, function(i, v) {
  1489.                                    
  1490.                                     // Reformat date display
  1491.                                     months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
  1492.                                     days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
  1493.                                    
  1494.                                     date = new Date(v);
  1495.                                     month = date.getMonth();
  1496.                                     day = date.getDate();
  1497.                                     year = date.getFullYear();
  1498.                                    
  1499.                                     $date_drop += '<option value="'+i+'">'+months[month] + ' ' + day + ', ' + year+'</option>';
  1500.                                 });
  1501.                                 $date_drop += '</select>';
  1502.                                 $('#revision_dates').html($date_drop);
  1503.                                
  1504.                                 // Reformat date display
  1505.                                 months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
  1506.                                 days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
  1507.                                
  1508.                                 date = new Date($date_changed);
  1509.                                 month = date.getMonth();
  1510.                                 long_day = date.getDay();
  1511.                                 day = date.getDate();
  1512.                                 year = date.getFullYear();
  1513.                                
  1514.                                 // Populate "date changed" heading
  1515.                                 $('#date_changed_title').hide().html('<strong>Date Changed:</strong> ' + days[long_day] + ', ' + months[month] + ' ' + day + ', ' + year).fadeIn();
  1516.                             });
  1517.                         },
  1518.                         onFormat: function (type) {
  1519.                            
  1520.                             switch (type) {
  1521.                                
  1522.                             case 'block':
  1523.    
  1524.                                 if (!this.active)
  1525.                                     return '<span class="disabled">' + this.value + '</span>';
  1526.                                 else if (this.value != this.page)
  1527.                                     return '<em><a href="#' + this.value + '">' + this.value + '</a></em>';
  1528.                                 return '<span class="current">' + this.value + '</span>';
  1529.                    
  1530.                             case 'next':
  1531.                    
  1532.                                 if (this.active)
  1533.                                     return '<a href="#' + this.value + '" class="next" title="Next">Next ></a>';
  1534.                                 return '<span class="disabled">Next ></span>';
  1535.                    
  1536.                             case 'prev':
  1537.                    
  1538.                                 if (this.active)
  1539.                                     return '<a href="#' + this.value + '" class="prev" title="Previous">< Prev</a>';
  1540.                                 return '<span class="disabled">< Prev</span>';
  1541.                    
  1542.                             case 'first':
  1543.                    
  1544.                                 if (this.active)
  1545.                                     return '<a href="#' + this.value + '" class="first" title="first">|<<</a>';
  1546.                                 return '<span class="disabled">|<<</span>';
  1547.                    
  1548.                             case 'last':
  1549.                    
  1550.                                 if (this.active)
  1551.                                     return '<a href="#' + this.value + '" class="last" title="Last">>>|</a>';
  1552.                                 return '<span class="disabled">>>|</span>';
  1553.                    
  1554.                             case "leap":
  1555.                    
  1556.                                 if (this.active)
  1557.                                     return "...";
  1558.                                 return "";
  1559.                    
  1560.                             case 'fill':
  1561.                    
  1562.                                 if (this.active)
  1563.                                     return " - ";
  1564.                                 return "";
  1565.                             }
  1566.                         }
  1567.                     });
  1568.                 }
  1569.                 // Else there are no results to paginate
  1570.                 else {
  1571.                    
  1572.                     // Clear revision html
  1573.                     $html = 'There are no revisions for this item.';
  1574.                     $('#revisions_ajax_div').html($html);
  1575.                    
  1576.                     // Clear pagination links
  1577.                     $(".pagination").html('');
  1578.                    
  1579.                     // Clear date dropdown
  1580.                     $('#revision_dates').html('');
  1581.                    
  1582.                     // Clear date title
  1583.                     $('#date_changed_title').html('');
  1584.                 }
  1585.             });
  1586.         });
  1587.        
  1588.         // Select revision date click function
  1589.         $(document).on('change', '#select_revision_date', function(e) {
  1590.            
  1591.             $page = parseInt($(this).val(), 10) + 1;
  1592.             paging.setPage($page);
  1593.         });
  1594.        
  1595.        
  1596.        
  1597.         // *****************************************************************************
  1598.         // Permissions Tab
  1599.         // *****************************************************************************
  1600.        
  1601.         // Save permissions
  1602.         $('#save_permissions').click(function() {
  1603.            
  1604.             // Get input values
  1605.             view_comp_profiles = $('#view_comp_profiles').val();
  1606.             view_prod_profiles = $('#view_prod_profiles').val();
  1607.             view_prod_summaries = $('#view_prod_summaries').val();
  1608.             perform_searches = $('#perform_searches').val();
  1609.             perform_adv_searches = $('#perform_adv_searches').val();
  1610.             view_prod_comp_comparisons = $('#view_prod_comp_comparisons').val();
  1611.             export_search_results = $('#export_search_results').val();
  1612.            
  1613.             $.ajax({
  1614.                 type: "POST",
  1615.                 url: '<?php echo base_url() . index_page(); ?>admin/save_permissions',
  1616.                 data: {view_comp_profiles: view_comp_profiles, view_prod_profiles: view_prod_profiles, view_prod_summaries: view_prod_summaries, perform_searches: perform_searches, perform_adv_searches: perform_adv_searches, view_prod_comp_comparisons: view_prod_comp_comparisons, export_search_results: export_search_results},
  1617.                 success: function(data){
  1618.                    
  1619.                     if(data.status == 'success') {
  1620.                        
  1621.                         $.alert({
  1622.                             title: 'Permissions Saved',
  1623.                             content: 'The user permissions have been saved successfully.',
  1624.                             columnClass: 'col-md-4 col-md-offset-4',
  1625.                             confirmButtonClass: 'btn-info'
  1626.                         });
  1627.                     }
  1628.                     if(data.status == 'update_failed') {
  1629.                        
  1630.                         $.alert({
  1631.                             title: 'Update Error',
  1632.                             content: 'An error was encountered while updating user permissions. Please contact a system administrator.',
  1633.                             columnClass: 'col-md-4 col-md-offset-4',
  1634.                             confirmButtonClass: 'btn-danger'
  1635.                         });
  1636.                     }
  1637.                 }
  1638.             });
  1639.         });
  1640.        
  1641.        
  1642.         // *****************************************************************************
  1643.         // Product Family Lookup Tab
  1644.         // *****************************************************************************
  1645.            
  1646.         var add_new_prod_form = '';
  1647.         var edit_prod_fam_form = '';
  1648.        
  1649.         // Dropdown change when selecting company
  1650.         $('#prod_fam_comp_select').on('change', function() {
  1651.            
  1652.             // Clear any appended items in step 2
  1653.             $('#prod_fam_prod_fam_select').html('');
  1654.            
  1655.             // Clear any appended items in product list
  1656.             $('#prod_fam_product_list').html('');
  1657.            
  1658.             // Get company id
  1659.             comp_id = $(this).val();
  1660.            
  1661.             // Fire ajax to get associated product families (select options for step 2)
  1662.             $.post("<?php echo base_url() . index_page(); ?>admin/prod_fam_get_produt_families_ajax", {comp_id: comp_id}).done(function(data) {
  1663.                
  1664.                 // Build assocaited produt family list
  1665.                 html = '<option value="">Select...</option>';
  1666.                 $.each(data, function(i, v) {
  1667.                    
  1668.                     if(v)
  1669.                         $.each(v, function(ii, vv) {
  1670.                            
  1671.                             html += '<option value="'+vv.product_family_id+'">'+vv.family_name+'</option>';
  1672.                         });
  1673.                 });
  1674.                
  1675.                 // Append select options to product family dropdown
  1676.                 $('#prod_fam_prod_fam_select').append(html);
  1677.             });
  1678.            
  1679.             // If this value is empty ("select..."); hide phase 2 & 3
  1680.             if(comp_id == '') {
  1681.            
  1682.                 // Hide product family select div
  1683.                 $('#prod_fam_prod_fam_select_div').hide();
  1684.                
  1685.                 // Hide product select dropdown div
  1686.                 $('#prod_fam_product_select_div').hide();
  1687.                
  1688.                 // Hide company products div
  1689.                 $('#prod_fam_fam_products_div').hide();
  1690.             }
  1691.             else {
  1692.            
  1693.                 // Show product family select div
  1694.                 $('#prod_fam_prod_fam_select_div').show();
  1695.                
  1696.                 // Show product select dropdown div
  1697.                 $('#prod_fam_product_select_div').show();
  1698.                
  1699.                 // Hide company products div
  1700.                 $('#prod_fam_fam_products_div').hide();
  1701.             }
  1702.         });
  1703.        
  1704.         // Dropdown change when selecting product family
  1705.         $('#prod_fam_prod_fam_select').on('change', function() {
  1706.            
  1707.             // Show company products div
  1708.             $('#prod_fam_fam_products_div').show();
  1709.            
  1710.             // Get product family id
  1711.             fam_id = $('#prod_fam_prod_fam_select').val();
  1712.            
  1713.             // Define return variable
  1714.             var $html = '';
  1715.            
  1716.             // Fire ajax to get products associcated with product family id
  1717.             $.post("<?php echo base_url() . index_page(); ?>admin/prod_fam_get_product_list", {fam_id: fam_id}).done(function(data) {
  1718.                
  1719.                 // If no results were found
  1720.                 if(data == 'no_results') {
  1721.                    
  1722.                     $html += 'No results found.';
  1723.                 }
  1724.                 // Else results were found
  1725.                 else {
  1726.                    
  1727.                     $html += '<table><tbody>';
  1728.                    
  1729.                     // Loop each result set and grab data
  1730.                     $.each(data, function(i, v) {
  1731.                        
  1732.                         $html += '<tr><td>' + v.product_name + '</td>' +
  1733.                                  '<td><span class="remove_product_from_family_list">Remove</span><span class="product_id" style="display:none;">' + v.product_id + '</span></td></tr>';
  1734.                     });
  1735.                    
  1736.                     $html += '</tbody></table>';
  1737.                 }
  1738.                    
  1739.                 // Populate product list
  1740.                 $('#prod_fam_product_list').html($html);
  1741.             });
  1742.         });
  1743.        
  1744.         // Add new product family
  1745.         $('#add_new_prod_family').click(function() {
  1746.            
  1747.             <?php
  1748.             // Get all company (name and id) for research company dropdown
  1749.             $sql = "SELECT * FROM company_profile ORDER BY firm_name ASC";
  1750.             $query = $this->Comman_crud->custom_query($sql);
  1751.             $all_comps = isset($query) ? (array)$query : array();
  1752.             ?>
  1753.            
  1754.             // Convert php results to json
  1755.             all_comps = <?php echo json_encode($all_comps) ?>;
  1756.             research_company_options = '';
  1757.            
  1758.             // Loop each company and build select list
  1759.             $.each(all_comps, function(i, v) {
  1760.                
  1761.                 research_company_options += '<option value="'+v.company_id+'">'+v.firm_name+'</option>';
  1762.             });
  1763.            
  1764.             // Add new produt family form
  1765.             $content_add_prod_fam =
  1766.                 'Use the form below to create a new product family.<br><br>' +
  1767.                 '<div>' +
  1768.                     '<table style="display:block;">' +
  1769.                     '<tbody>' +
  1770.                         '<tr>' +
  1771.                             '<td>Family Name</td>' +
  1772.                             '<td><input type="text" id="family_name" style="width:100%;" /></td>' +
  1773.                         '</tr>' +
  1774.                         '<tr>' +
  1775.                             '<td>Family URL</td>' +
  1776.                             '<td><input type="text" id="family_url" style="width:100%;" /></td>' +
  1777.                         '</tr>' +
  1778.                         '<tr>' +
  1779.                             '<td>Family Description</td>' +
  1780.                             '<td><input type="text" id="family_description" style="width:100%;" /></td>' +
  1781.                         '</tr>' +
  1782.                         '<tr>' +
  1783.                             '<td>Number of Products</td>' +
  1784.                             '<td><input type="text" id="num_products" style="width:100%;" /></td>' +
  1785.                         '</tr>' +
  1786.                         '<tr>' +
  1787.                             '<td>Family Issue Coverage</td>' +
  1788.                             '<td>' +
  1789.                                 '<select id="family_issue_coverage" style="width:100%;">' +
  1790.                                     '<option value="">Select...</option>' +
  1791.                                     '<option value="E">Environmental</option>' +
  1792.                                     '<option value="S">Social</option>' +
  1793.                                     '<option value="G">Governance</option>' +
  1794.                                     '<option value="ES">Environmental & Social</option>' +
  1795.                                     '<option value="EG">Environmental & Governance</option>' +
  1796.                                     '<option value="SG">Social & Governance</option>' +
  1797.                                     '<option value="ESG">Environmental, Social & Governance</option>' +
  1798.                                 '</select>' +
  1799.                             '</td>' +
  1800.                         '</tr>' +
  1801.                         '<tr>' +
  1802.                             '<td>Product Type</td>' +
  1803.                             '<td>' +
  1804.                                 '<select id="product_type" style="width:100%;">' +
  1805.                                     '<option value="">Select...</option>' +
  1806.                                     '<option value="index">Index</option>' +
  1807.                                     '<option value="ranking">Ranking</option>' +
  1808.                                     '<option value="rating">Rating</option>' +
  1809.                                 '</select>' +
  1810.                             '</td>' +
  1811.                         '</tr>' +
  1812.                         '<tr>' +
  1813.                             '<td>Target Audience</td>' +
  1814.                             '<td>' +
  1815.                                 '<select id="target_audience" style="width:100%;">' +
  1816.                                     '<option value="">Select...</option>' +
  1817.                                     '<option value="consumers">Consumers</option>' +
  1818.                                     '<option value="investors">Investors</option>' +
  1819.                                     '<option value="companies">Companies</option>' +
  1820.                                 '</select>' +
  1821.                             '</td>' +
  1822.                         '</tr>' +
  1823.                         '<tr>' +
  1824.                             '<td>Number of Companies Covered</td>' +
  1825.                             '<td><input type="text" id="num_companies_covered" style="width:100%;" /></td>' +
  1826.                         '</tr>' +
  1827.                         '<tr>' +
  1828.                             '<td>Research Company</td>' +
  1829.                             '<td>' +
  1830.                                 '<select id="research_company_id" style="max-width:300px;">' +
  1831.                                     '<option value="">Select...</option>' +
  1832.                                     research_company_options +
  1833.                                 '</select>' +
  1834.                             '</td>' +
  1835.                         '</tr>' +
  1836.                     '</tbody>' +
  1837.                     '</table>' +
  1838.                 '</div>'
  1839.             ;
  1840.            
  1841.             // Add new product family alert
  1842.             add_new_prod_form = $.confirm({
  1843.                 title: 'Create Product Family',
  1844.                 content: $content_add_prod_fam,
  1845.                 columnClass: 'col-md-6 col-md-offset-3',
  1846.                 confirmButtonClass: 'btn-info',
  1847.                 cancelButtonClass: 'btn-danger',
  1848.                 confirmButton: 'Save Product Family',
  1849.                 confirm: function() {
  1850.                    
  1851.                     // Get form values
  1852.                     var family_name = this.$b.find('#family_name').val();
  1853.                     var family_url = this.$b.find('#family_url').val();
  1854.                     var family_description = this.$b.find('#family_description').val();
  1855.                     var num_products = this.$b.find('#num_products').val();
  1856.                     var family_issue_coverage = this.$b.find('#family_issue_coverage').val();
  1857.                     var product_type = this.$b.find('#product_type').val();
  1858.                     var target_audience = this.$b.find('#target_audience').val();
  1859.                     var num_companies_covered = this.$b.find('#num_companies_covered').val();
  1860.                     var research_company_id = this.$b.find('#research_company_id').val();
  1861.                     var company_id = $('#prod_fam_comp_select').val();
  1862.                    
  1863.                     // Ensure no form values are empty
  1864.                     if(family_name == '' || family_url == '' || family_description == '' || num_products == '' || family_issue_coverage == '' || product_type == '' || target_audience == '' || num_companies_covered == '' || research_company_id == '') {
  1865.                        
  1866.                         // Alert user all fields are required
  1867.                         $.alert({
  1868.                             title: 'Fields Incomplete',
  1869.                             content: 'All fields are required for submission.',
  1870.                             columnClass: 'col-md-6 col-md-offset-3',
  1871.                             confirmButtonClass: 'btn-danger'
  1872.                         });
  1873.                        
  1874.                         return false;
  1875.                     }
  1876.                    
  1877.                     // Ensure product family name does not already exist (associated with company id) (can have two product families with same name - as long as company is different)
  1878.                     $.post("<?php echo base_url() . index_page(); ?>admin/prod_fam_add_new_check_fam_name", {family_name: family_name, company_id: company_id}).done(function(data) {
  1879.                        
  1880.                         // If this product family name exists
  1881.                         if(data == 'true') {
  1882.                        
  1883.                             // Alert user product family name exists
  1884.                             $.alert({
  1885.                                 title: 'Product Family Name Exists',
  1886.                                 content: 'This product family name already exists for this company. Please enter a unique product family name.',
  1887.                                 columnClass: 'col-md-6 col-md-offset-3',
  1888.                                 confirmButtonClass: 'btn-danger'
  1889.                             });
  1890.                         }
  1891.                         // Else we are good to save
  1892.                         else {
  1893.                            
  1894.                             // Save new product family
  1895.                             $.post("<?php echo base_url() . index_page(); ?>admin/prod_fam_save_new_prod_fam", {family_name: family_name, family_url: family_url, family_description: family_description, num_products: num_products, family_issue_coverage: family_issue_coverage, product_type: product_type, target_audience: target_audience, num_companies_covered: num_companies_covered, research_company_id: research_company_id, company_id: company_id}).done(function(data) {
  1896.                                
  1897.                                 // If product family was added successfully
  1898.                                 if(data == 'success') {
  1899.                                    
  1900.                                     // Alert product family saved successfully
  1901.                                     $.alert({
  1902.                                         title: 'Product Family Saved',
  1903.                                         content: 'This product family has been saved successfully.',
  1904.                                         columnClass: 'col-md-6 col-md-offset-3',
  1905.                                         confirmButtonClass: 'btn-info',
  1906.                                         confirm: function() {
  1907.                                    
  1908.                                             // Close form
  1909.                                             add_new_prod_form.close();
  1910.                                            
  1911.                                             // Reload page
  1912.                                             location.reload();
  1913.                                         }
  1914.                                     });
  1915.                                 }
  1916.                                 else if(data == 'fail') {
  1917.                                    
  1918.                                     // Alert product family saved successfully
  1919.                                     $.alert({
  1920.                                         title: 'Product Family Save Fail',
  1921.                                         content: 'An error was encountered while saving this product family. Please contact a system administrator.',
  1922.                                         columnClass: 'col-md-6 col-md-offset-3',
  1923.                                         confirmButtonClass: 'btn-danger'
  1924.                                     });
  1925.                                 }
  1926.                             });
  1927.                         }
  1928.                     });
  1929.                    
  1930.                     // Keep original dialog open (must be closed manually)
  1931.                     return false;
  1932.                 }
  1933.             });
  1934.         });
  1935.        
  1936.         // Edit product family
  1937.         $('#edit_prod_family').click(function() {
  1938.            
  1939.             // Get product family id
  1940.             prod_fam_id = $('#prod_fam_prod_fam_select').val();
  1941.            
  1942.             // If a product family is not selected
  1943.             if(prod_fam_id == '') {
  1944.                
  1945.                 // Alert product family not selected
  1946.                 $.alert({
  1947.                     title: 'Product Family Not Selected',
  1948.                     content: 'Please select a product family to edit.',
  1949.                     columnClass: 'col-md-6 col-md-offset-3',
  1950.                     confirmButtonClass: 'btn-danger'
  1951.                 });
  1952.                
  1953.                 return false;
  1954.             }
  1955.            
  1956.             // Get product family info from database
  1957.             $.post("<?php echo base_url() . index_page(); ?>admin/prod_fam_get_prod_fam_info", {prod_fam_id: prod_fam_id}).done(function(data) {
  1958.                
  1959.                 // If a result was returned
  1960.                 if(data !== '') {
  1961.                    
  1962.                     <?php
  1963.                     // Get all company (name and id) for research company dropdown
  1964.                     $sql = "SELECT * FROM company_profile ORDER BY firm_name ASC";
  1965.                     $query = $this->Comman_crud->custom_query($sql);
  1966.                     $all_comps = isset($query) ? (array)$query : array();
  1967.                     ?>
  1968.                    
  1969.                     // Convert php results to json
  1970.                     all_comps = <?php echo json_encode($all_comps) ?>;
  1971.                     research_company_options = '';
  1972.                    
  1973.                     // Loop each (research) company and build select list
  1974.                     $.each(all_comps, function(i, v) {
  1975.                        
  1976.                         // If this company id = returned data research company id
  1977.                         selected = v.company_id == data.results.research_company_id ? 'selected="selected"' : '';
  1978.                         research_company_options += '<option value="'+v.company_id+'" ' + selected + '>'+v.firm_name+'</option>';
  1979.                     });
  1980.                    
  1981.                     // Set from select values
  1982.                     fia_default = data.results.family_issue_converage == "" ? 'selected="selected"' : '';
  1983.                     fia_E = data.results.family_issue_converage == "E" ? 'selected="selected"' : '';
  1984.                     fia_S = data.results.family_issue_converage == "S" ? 'selected="selected"' : '';
  1985.                     fia_G = data.results.family_issue_converage == "G" ? 'selected="selected"' : '';
  1986.                     fia_ES = data.results.family_issue_converage == "ES" ? 'selected="selected"' : '';
  1987.                     fia_EG = data.results.family_issue_converage == "EG" ? 'selected="selected"' : '';
  1988.                     fia_SG = data.results.family_issue_converage == "SG" ? 'selected="selected"' : '';
  1989.                     fia_ESG = data.results.family_issue_converage == "ESG" ? 'selected="selected"' : '';
  1990.                    
  1991.                     pt_default = data.results.product_type == "" ? 'selected="selected"' : '';
  1992.                     pt_index = data.results.product_type == "index" ? 'selected="selected"' : '';
  1993.                     pt_ranking = data.results.product_type == "ranking" ? 'selected="selected"' : '';
  1994.                     pt_rating = data.results.product_type == "rating" ? 'selected="selected"' : '';
  1995.                    
  1996.                     ta_default = data.results.target_audience == "" ? 'selected="selected"' : '';
  1997.                     ta_consumers = data.results.target_audience == "consumers" ? 'selected="selected"' : '';
  1998.                     ta_investors = data.results.target_audience == "investors" ? 'selected="selected"' : '';
  1999.                     ta_companies = data.results.target_audience == "companies" ? 'selected="selected"' : '';
  2000.                    
  2001.                     // Build edit form
  2002.                     // Add new produt family form
  2003.                     $content_edit_prod_fam_form =
  2004.                         'Use the form below to edit this product family.<br><br>' +
  2005.                         '<div>' +
  2006.                             '<table style="display:block;">' +
  2007.                             '<tbody>' +
  2008.                                 '<tr>' +
  2009.                                     '<td>Family Name</td>' +
  2010.                                     '<td><input type="text" id="family_name" style="width:100%;" value="'+data.results.family_name+'" /></td>' +
  2011.                                 '</tr>' +
  2012.                                 '<tr>' +
  2013.                                     '<td>Family URL</td>' +
  2014.                                     '<td><input type="text" id="family_url" style="width:100%;" value="'+data.results.family_url+'" /></td>' +
  2015.                                 '</tr>' +
  2016.                                 '<tr>' +
  2017.                                     '<td>Family Description</td>' +
  2018.                                     '<td><input type="text" id="family_description" style="width:100%;" value="'+data.results.family_description+'" /></td>' +
  2019.                                 '</tr>' +
  2020.                                 '<tr>' +
  2021.                                     '<td>Number of Products</td>' +
  2022.                                     '<td><input type="text" id="num_products" style="width:100%;" value="'+data.results.num_products+'" /></td>' +
  2023.                                 '</tr>' +
  2024.                                 '<tr>' +
  2025.                                     '<td>Family Issue Coverage</td>' +
  2026.                                     '<td>' +
  2027.                                         '<select id="family_issue_coverage" style="width:100%;">' +
  2028.                                             '<option value="" ' + fia_default + '>Select...</option>' +
  2029.                                             '<option value="E" ' + fia_E + '>Environmental</option>' +
  2030.                                             '<option value="S" ' + fia_S + '>Social</option>' +
  2031.                                             '<option value="G" ' + fia_G + '>Governance</option>' +
  2032.                                             '<option value="ES" ' + fia_ES + '>Environmental & Social</option>' +
  2033.                                             '<option value="EG" ' + fia_EG + '>Environmental & Governance</option>' +
  2034.                                             '<option value="SG" ' + fia_SG + '>Social & Governance</option>' +
  2035.                                             '<option value="ESG" ' + fia_ESG + '>Environmental, Social & Governance</option>' +
  2036.                                         '</select>' +
  2037.                                     '</td>' +
  2038.                                 '</tr>' +
  2039.                                 '<tr>' +
  2040.                                     '<td>Product Type</td>' +
  2041.                                     '<td>' +
  2042.                                         '<select id="product_type" style="width:100%;">' +
  2043.                                             '<option value="" ' + pt_default + '>Select...</option>' +
  2044.                                             '<option value="index" ' + pt_index + '>Index</option>' +
  2045.                                             '<option value="ranking" ' + pt_ranking + '>Ranking</option>' +
  2046.                                             '<option value="rating" ' + pt_rating + '>Rating</option>' +
  2047.                                         '</select>' +
  2048.                                     '</td>' +
  2049.                                 '</tr>' +
  2050.                                 '<tr>' +
  2051.                                     '<td>Target Audience</td>' +
  2052.                                     '<td>' +
  2053.                                         '<select id="target_audience" style="width:100%;">' +
  2054.                                             '<option value="" ' + ta_default + '>Select...</option>' +
  2055.                                             '<option value="consumers" ' + ta_consumers + '>Consumers</option>' +
  2056.                                             '<option value="investors" ' + ta_investors + '>Investors</option>' +
  2057.                                             '<option value="companies" ' + ta_companies + '>Companies</option>' +
  2058.                                         '</select>' +
  2059.                                     '</td>' +
  2060.                                 '</tr>' +
  2061.                                 '<tr>' +
  2062.                                     '<td>Number of Companies Covered</td>' +
  2063.                                     '<td><input type="text" id="num_companies_covered" style="width:100%;" value="'+data.results.num_companies_covered+'" /></td>' +
  2064.                                 '</tr>' +
  2065.                                 '<tr>' +
  2066.                                     '<td>Research Company</td>' +
  2067.                                     '<td>' +
  2068.                                         '<select id="research_company_id" style="max-width:300px;">' +
  2069.                                             '<option value="">Select...</option>' +
  2070.                                             research_company_options +
  2071.                                         '</select>' +
  2072.                                     '</td>' +
  2073.                                 '</tr>' +
  2074.                             '</tbody>' +
  2075.                             '</table>' +
  2076.                         '</div>'
  2077.                     ;
  2078.                 }
  2079.            
  2080.                 // Edit product family alert
  2081.                 edit_prod_fam_form = $.confirm({
  2082.                     title: 'Update Product Family',
  2083.                     content: $content_edit_prod_fam_form,
  2084.                     columnClass: 'col-md-6 col-md-offset-3',
  2085.                     confirmButtonClass: 'btn-info',
  2086.                     cancelButtonClass: 'btn-danger',
  2087.                     confirmButton: 'Update Product Family',
  2088.                     confirm: function() {
  2089.                        
  2090.                         // Get form values
  2091.                         var family_name = this.$b.find('#family_name').val();
  2092.                         var family_url = this.$b.find('#family_url').val();
  2093.                         var family_description = this.$b.find('#family_description').val();
  2094.                         var num_products = this.$b.find('#num_products').val();
  2095.                         var family_issue_coverage = this.$b.find('#family_issue_coverage').val();
  2096.                         var product_type = this.$b.find('#product_type').val();
  2097.                         var target_audience = this.$b.find('#target_audience').val();
  2098.                         var num_companies_covered = this.$b.find('#num_companies_covered').val();
  2099.                         var research_company_id = this.$b.find('#research_company_id').val();
  2100.                         var company_id = $('#prod_fam_comp_select').val();
  2101.                         var product_family_id = $('#prod_fam_prod_fam_select').val();
  2102.                        
  2103.                         // Ensure no form values are empty
  2104.                         if(family_name == '' || family_url == '' || family_description == '' || num_products == '' || family_issue_coverage == '' || product_type == '' || target_audience == '' || num_companies_covered == '' || research_company_id == '') {
  2105.                            
  2106.                             // Alert user all fields are required
  2107.                             $.alert({
  2108.                                 title: 'Fields Incomplete',
  2109.                                 content: 'All fields are required for submission.',
  2110.                                 columnClass: 'col-md-6 col-md-offset-3',
  2111.                                 confirmButtonClass: 'btn-danger'
  2112.                             });
  2113.                            
  2114.                             return false;
  2115.                         }
  2116.                        
  2117.                         // Update product family
  2118.                         $.post("<?php echo base_url() . index_page(); ?>admin/prod_fam_update_prod_fam", {family_name: family_name, family_url: family_url, family_description: family_description, num_products: num_products, family_issue_coverage: family_issue_coverage, product_type: product_type, target_audience: target_audience, num_companies_covered: num_companies_covered, research_company_id: research_company_id, company_id: company_id, product_family_id: product_family_id}).done(function(data) {
  2119.                            
  2120.                             // If product family was added successfully
  2121.                             if(data == 'success') {
  2122.                                
  2123.                                 // Alert user product family updated
  2124.                                 $.alert({
  2125.                                     title: 'Product Family Updated',
  2126.                                     content: 'This product family was updated successfully.',
  2127.                                     columnClass: 'col-md-6 col-md-offset-3',
  2128.                                     confirmButtonClass: 'btn-info'
  2129.                                 });
  2130.                             }
  2131.                             else {
  2132.                                
  2133.                                 // Alert user product family update failed
  2134.                                 $.alert({
  2135.                                     title: 'Product Family Update Failed',
  2136.                                     content: 'An error was encounted while updating this product family. Please contact a system administrator.',
  2137.                                     columnClass: 'col-md-6 col-md-offset-3',
  2138.                                     confirmButtonClass: 'btn-info'
  2139.                                 });
  2140.                             }
  2141.                            
  2142.                             // Close form
  2143.                             edit_prod_fam_form.close();
  2144.                         });
  2145.                    
  2146.                         // Keep original dialog open (must be closed manually)
  2147.                         return false;
  2148.                     }
  2149.                 });
  2150.             });
  2151.         });
  2152.        
  2153.         // Deactivate product family
  2154.         $('#deacivate_prod_family').click(function() {
  2155.                    
  2156.             var product_family_id = $('#prod_fam_prod_fam_select').val();
  2157.            
  2158.             // If product family id is empty
  2159.             if(product_family_id == '') {
  2160.                
  2161.                 // Alert user product family not selected
  2162.                 $.alert({
  2163.                     title: 'Select Product Family',
  2164.                     content: 'A product family must first be selected.',
  2165.                     columnClass: 'col-md-6 col-md-offset-3',
  2166.                     confirmButtonClass: 'btn-danger'
  2167.                 });
  2168.                
  2169.                 return false;
  2170.             }
  2171.            
  2172.             $.confirm({
  2173.                 title: 'Deactivate Product Family',
  2174.                 content: 'This product family will be deactivated. All associated products will also be deactivated.',
  2175.                 columnClass: 'col-md-6 col-md-offset-3',
  2176.                 confirmButtonClass: 'btn-info',
  2177.                 cancelButtonClass: 'btn-danger',
  2178.                 confirmButton: 'Deactivate',
  2179.                 confirm: function() {
  2180.                    
  2181.                     // Fire ajax to deactivate product family
  2182.                     $.post("<?php echo base_url() . index_page(); ?>admin/prod_fam_deactivate_fam_prod", {product_family_id: product_family_id}).done(function(data) {
  2183.                        
  2184.                         // If family product was deactivated successfully
  2185.                         if(data == 'success') {
  2186.                            
  2187.                             // Alert user product family deactivated
  2188.                             $.alert({
  2189.                                 title: 'Product Family Deactivated',
  2190.                                 content: 'This product family was deacivated successfully.',
  2191.                                 columnClass: 'col-md-6 col-md-offset-3',
  2192.                                 confirmButtonClass: 'btn-info',
  2193.                                 confirm: function() {
  2194.                                    
  2195.                                     // Reload page
  2196.                                     location.reload();
  2197.                                 }
  2198.                             });
  2199.                         }
  2200.                         else {
  2201.                            
  2202.                             // Alert user family product deactivated failed
  2203.                             $.alert({
  2204.                                 title: 'Product Family Deactivation Failed',
  2205.                                 content: 'An error was encounted while deactivating this family product. Please contact a system administrator.',
  2206.                                 columnClass: 'col-md-6 col-md-offset-3',
  2207.                                 confirmButtonClass: 'btn-danger'
  2208.                             });
  2209.                         }
  2210.                     });
  2211.                 }
  2212.             });
  2213.         });
  2214.        
  2215.         // Reactivate product family
  2216.         $(document).on('click', '.reactivate_product_family', function() {
  2217.            
  2218.             // Get product family id
  2219.             product_family_id = $(this).attr('id');
  2220.            
  2221.             $.confirm({
  2222.                 title: 'Reactivate Product Family',
  2223.                 content: 'This product family will be Reactivated.<br /><br />Should all associated products also be reactivated?<br /><table style="display:block;"><tbody><tr><td><input type="checkbox" id="reactivate_all_prods" /></td><td style="vertical-align:bottom;">Yes</td></tr></tbody></table>',
  2224.                 columnClass: 'col-md-6 col-md-offset-3',
  2225.                 confirmButtonClass: 'btn-info',
  2226.                 cancelButtonClass: 'btn-danger',
  2227.                 confirmButton: 'Reactivate',
  2228.                 confirm: function() {
  2229.                    
  2230.                     // Check if reactivating all products
  2231.                     reactivate_all_prods = this.$b.find('#reactivate_all_prods').is(':checked') ? 'true' : 'false';
  2232.            
  2233.                     // Fire ajax to reactivate product family (and products)
  2234.                     $.post("<?php echo base_url() . index_page(); ?>admin/prod_fam_reactivate_fam_prod", {product_family_id: product_family_id, reactivate_all_prods: reactivate_all_prods}).done(function(data) {
  2235.                                
  2236.                         // If family product was reactivated successfully
  2237.                         if(data == 'success') {
  2238.                            
  2239.                             // Alert user product family reactivated
  2240.                             $.alert({
  2241.                                 title: 'Product Family Reactivated',
  2242.                                 content: 'This product family was reactivated successfully.',
  2243.                                 columnClass: 'col-md-6 col-md-offset-3',
  2244.                                 confirmButtonClass: 'btn-info',
  2245.                                 confirm: function() {
  2246.                                    
  2247.                                     // Reload page
  2248.                                     location.reload();
  2249.                                 }
  2250.                             });
  2251.                         }
  2252.                         else {
  2253.                            
  2254.                             // Alert user family product reactivated failed
  2255.                             $.alert({
  2256.                                 title: 'Product Family Reactivation Failed',
  2257.                                 content: 'An error was encounted while reactivating this family product. Please contact a system administrator.',
  2258.                                 columnClass: 'col-md-6 col-md-offset-3',
  2259.                                 confirmButtonClass: 'btn-danger'
  2260.                             });
  2261.                         }
  2262.                     });
  2263.                 }
  2264.             });
  2265.         });
  2266.        
  2267.         // Remove product from product list
  2268.         $(document).on('click', '.remove_product_from_family_list', function() {
  2269.            
  2270.             var $this = $(this);
  2271.            
  2272.             // Confirm remove product from product family
  2273.             $.confirm({
  2274.                 title: 'Remove Product Family',
  2275.                 content: 'This action will remove the product family associated with this product.',
  2276.                 columnClass: 'col-md-6 col-md-offset-3',
  2277.                 confirmButtonClass: 'btn-info',
  2278.                 cancelButtonClass: 'btn-danger',
  2279.                 confirmButton: 'Remove Family',
  2280.                 confirm: function() {
  2281.                    
  2282.                     // Get product id
  2283.                     prod_id = $($this).siblings('.product_id').text();
  2284.                     // Get product family id
  2285.                     prod_fam_id = $('#prod_fam_prod_fam_select').val();
  2286.                    
  2287.                     // Fire ajax to delete product family id
  2288.                     $.post("<?php echo base_url() . index_page(); ?>admin/prod_fam_delete_prod_fam_id", {prod_id: prod_id, prod_fam_id: prod_fam_id}).done(function(data) {
  2289.                        
  2290.                         if(data == 'success') {
  2291.                            
  2292.                             // Alert product family removed
  2293.                             $.alert({
  2294.                                 title: 'Product Family Removed',
  2295.                                 content: 'This products family was removed successfully.',
  2296.                                 columnClass: 'col-md-6 col-md-offset-3',
  2297.                                 confirmButtonClass: 'btn-info',
  2298.                                 confirm: function() {
  2299.                                    
  2300.                                     // Remove tr row
  2301.                                     $($this).parent().parent().remove();
  2302.                                 }
  2303.                             });
  2304.                         }
  2305.                         else {
  2306.                            
  2307.                             // Alert error removing product family
  2308.                             $.alert({
  2309.                                 title: 'Product Family Removal Failed',
  2310.                                 content: 'An error was encounted while reactivating this products family. Please contact a system administrator.',
  2311.                                 columnClass: 'col-md-6 col-md-offset-3',
  2312.                                 confirmButtonClass: 'btn-danger'
  2313.                             });
  2314.                         }
  2315.                     });
  2316.                 }
  2317.             });
  2318.         });
  2319.        
  2320.         // Add product to family
  2321.         $('#add_prod_to_fam').click(function() {
  2322.            
  2323.             // Get product family id
  2324.             prod_fam_id = $('#prod_fam_prod_fam_select').val();
  2325.            
  2326.             // Get company id
  2327.             comp_id = $('#prod_fam_comp_select').val();
  2328.            
  2329.             // If a product family is not selected
  2330.             if(prod_fam_id == '') {
  2331.                
  2332.                 // Alert product family not selected
  2333.                 $.alert({
  2334.                     title: 'Product Family Not Selected',
  2335.                     content: 'Please select a product family.',
  2336.                     columnClass: 'col-md-6 col-md-offset-3',
  2337.                     confirmButtonClass: 'btn-danger'
  2338.                 });
  2339.                
  2340.                 return false;
  2341.             }
  2342.            
  2343.             // Fire ajax to get all products assocaited with company
  2344.             $.post("<?php echo base_url() . index_page(); ?>admin/get_all_prods_add_to_family", {comp_id: comp_id}).done(function(data) {
  2345.                
  2346.                 // Create html to return to form
  2347.                 var $html = '';
  2348.                
  2349.                 if(data == 'no_results') {
  2350.                    
  2351.                     $html += 'No results found.';  
  2352.                 }
  2353.                 else {
  2354.                    
  2355.                     $html += '<table><tbody>';
  2356.                     $.each(data, function(i, v) {
  2357.                        
  2358.                         // Check if this family has a name
  2359.                         fam_name = v.pfl_family_name ? v.pfl_family_name : '<span style="color:red;">None Assigned</span>';
  2360.                        
  2361.                         $html += '<tr><td><strong>Product Name:</strong> ' + v.product_name + '<br /><strong>Current Product Family:</strong> ' + fam_name + '</td>' +
  2362.                                  '<td>' +
  2363.                                     '<span class="add_product_to_family">Add</span>' +
  2364.                                     '<span class="add_product_to_family_prod_id" style="display:none;">' + v.product_id + '</span>' +
  2365.                                     '<span class="add_product_to_family_prod_fam_id_orig" style="display:none;">' + v.product_family_id + '</span>';
  2366.                                 '</td></tr>';
  2367.                     });
  2368.                     $html += '</tbody></table>';
  2369.                 }
  2370.                
  2371.                 $.alert({
  2372.                     title: 'Select Product',
  2373.                     content: 'Select a product to add to this product family.<br /><br />' + $html,
  2374.                     columnClass: 'col-md-6 col-md-offset-3',
  2375.                     confirmButtonClass: 'btn-danger close_main_add_prod_to_fam_overlay',
  2376.                     confirmButton: 'Cancel'
  2377.                 });
  2378.             });
  2379.         });
  2380.         // Bind to add product button
  2381.         $(document).on('click', '.add_product_to_family', function() {
  2382.            
  2383.             var $this_add_product = $(this);
  2384.            
  2385.             // Confirm add product to product family
  2386.             $.confirm({
  2387.                 title: 'Add Product to Family',
  2388.                 content: 'This action will add this product to the currently selected product family.<br /><br />If this product is already tied to another product family; the product will be removed from that product family, and tied to this one.',
  2389.                 columnClass: 'col-md-6 col-md-offset-3',
  2390.                 confirmButtonClass: 'btn-info',
  2391.                 cancelButtonClass: 'btn-danger',
  2392.                 confirmButton: 'Add Product',
  2393.                 confirm: function() {
  2394.                
  2395.                     // Get product id
  2396.                     prod_id = $($this_add_product).siblings('.add_product_to_family_prod_id').text();
  2397.                     // Get original product family id (from hidden span)
  2398.                     prod_fam_id_orig = $($this_add_product).siblings('.add_product_to_family_prod_fam_id_orig').text();
  2399.                     // Get new product family id (from selection)
  2400.                     prod_fam_id_new = $('#prod_fam_prod_fam_select').val();
  2401.                    
  2402.                     // Fire ajax to adjust products family association
  2403.                     $.post("<?php echo base_url() . index_page(); ?>admin/add_product_to_product_family", {prod_id: prod_id, prod_fam_id_orig: prod_fam_id_orig, prod_fam_id_new: prod_fam_id_new}).done(function(data) {
  2404.                        
  2405.                         if(data == 'success') {
  2406.                            
  2407.                             // Alert product added to product family
  2408.                             $.alert({
  2409.                                 title: 'Product Added to Family',
  2410.                                 content: 'This product was successfully added to the product family.',
  2411.                                 columnClass: 'col-md-6 col-md-offset-3',
  2412.                                 confirmButtonClass: 'btn-info'
  2413.                             });
  2414.                         }
  2415.                         else {
  2416.                            
  2417.                             // Alert error adding product to family
  2418.                             $.alert({
  2419.                                 title: 'Product Family Addition Failed',
  2420.                                 content: 'An error was encounted while adding this product to the product family. Please contact a system administrator.',
  2421.                                 columnClass: 'col-md-6 col-md-offset-3',
  2422.                                 confirmButtonClass: 'btn-danger'
  2423.                             });
  2424.                         }
  2425.                    
  2426.                         // Close main dialog
  2427.                         $('.close_main_add_prod_to_fam_overlay').click();
  2428.                         // Refresh family product list
  2429.                         $('#prod_fam_prod_fam_select').change();
  2430.                     });
  2431.                 }
  2432.             });
  2433.         });
  2434.        
  2435.        
  2436.         // *****************************************************************************
  2437.         // Data Fields Tab
  2438.         // *****************************************************************************
  2439.        
  2440.         // Show/hid divs
  2441.         $('#add_edit_comp_toggle').click(function() {
  2442.            
  2443.             $('.add_edit_comp_div').slideToggle();
  2444.            
  2445.             // Adjust class to keep active
  2446.             if($(this).hasClass('data_fields_active')) {
  2447.                 $(this).removeClass('data_fields_active');
  2448.             }
  2449.             else {
  2450.                 $(this).addClass('data_fields_active');
  2451.             }
  2452.         });
  2453.         $('#add_edit_prod_toggle').click(function() {
  2454.            
  2455.             $('.add_edit_prod_div').slideToggle();
  2456.            
  2457.             // Adjust class to keep active
  2458.             if($(this).hasClass('data_fields_active')) {
  2459.                 $(this).removeClass('data_fields_active');
  2460.             }
  2461.             else {
  2462.                 $(this).addClass('data_fields_active');
  2463.             }
  2464.         });
  2465.         $('#comp_profile_toggle').click(function() {
  2466.            
  2467.             $('.comp_profile_div').slideToggle();
  2468.            
  2469.             // Adjust class to keep active
  2470.             if($(this).hasClass('data_fields_active')) {
  2471.                 $(this).removeClass('data_fields_active');
  2472.             }
  2473.             else {
  2474.                 $(this).addClass('data_fields_active');
  2475.             }
  2476.         });
  2477.         $('#prod_profile_toggle').click(function() {
  2478.            
  2479.             $('.prod_profile_div').slideToggle();
  2480.            
  2481.             // Adjust class to keep active
  2482.             if($(this).hasClass('data_fields_active')) {
  2483.                 $(this).removeClass('data_fields_active');
  2484.             }
  2485.             else {
  2486.                 $(this).addClass('data_fields_active');
  2487.             }
  2488.         });
  2489.        
  2490.         // Save data fields
  2491.         $('.save_data_fields').click(function() {
  2492.            
  2493.             // Get all add/edit company fields
  2494.             data_fields_add_edit_comp = {};
  2495.             // Get all add/edit product fields
  2496.             data_fields_add_edit_prod = {};
  2497.             // Get all company profile fields
  2498.             data_fields_comp_profile = {};
  2499.             // Get all product profile fields
  2500.             data_fields_prod_profile = {};
  2501.            
  2502.             // Loop each add/edit company field and create object
  2503.             $.each($('.textarea_data_field.add_edit_comp'), function(i, v) {
  2504.                
  2505.                 data_fields_add_edit_comp[$(this).attr('id')] = $(this).val();
  2506.             });
  2507.            
  2508.             // Loop each add/edit product field and create object
  2509.             $.each($('.textarea_data_field.add_edit_prod'), function(i, v) {
  2510.                
  2511.                 data_fields_add_edit_prod[$(this).attr('id')] = $(this).val();
  2512.             });
  2513.            
  2514.             // Loop each company profile field and create object
  2515.             $.each($('.textarea_data_field.comp_profile'), function(i, v) {
  2516.                
  2517.                 data_fields_comp_profile[$(this).attr('id')] = $(this).val();
  2518.             });
  2519.            
  2520.             // Loop each product profile field and create object
  2521.             $.each($('.textarea_data_field.prod_profile'), function(i, v) {
  2522.                
  2523.                 data_fields_prod_profile[$(this).attr('id')] = $(this).val();
  2524.             });
  2525.            
  2526.             // Fire ajax to update options
  2527.             $.post("<?php echo base_url() . index_page(); ?>admin/save_data_fields", {data_fields_add_edit_comp: data_fields_add_edit_comp, data_fields_add_edit_prod: data_fields_add_edit_prod, data_fields_comp_profile: data_fields_comp_profile, data_fields_prod_profile: data_fields_prod_profile}).done(function(data) {
  2528.                
  2529.                 // If data fields were updated successfully
  2530.                 if(data == 'success') {
  2531.                    
  2532.                     // Alert user data fields updated
  2533.                     $.alert({
  2534.                         title: 'Data Fields Updated',
  2535.                         content: 'The data fields were updated successfully.',
  2536.                         columnClass: 'col-md-6 col-md-offset-3',
  2537.                         confirmButtonClass: 'btn-info'
  2538.                     });
  2539.                 }
  2540.                 else {
  2541.                    
  2542.                     // Alert user data fields update failed
  2543.                     $.alert({
  2544.                         title: 'Data Fields Update Failed',
  2545.                         content: 'An error was encountered while updating the data fields. Please contact a system administrator.',
  2546.                         columnClass: 'col-md-6 col-md-offset-3',
  2547.                         confirmButtonClass: 'btn-danger'
  2548.                     });
  2549.                 }
  2550.             });
  2551.         });
  2552.        
  2553.         // *****************************************************************************
  2554.         // Misc Tab
  2555.         // *****************************************************************************
  2556.        
  2557.         // Company pdf populate filename
  2558.         $("#upload_comp_pdf_button").on("change", function () {
  2559.            
  2560.             // Show filename and remove fields
  2561.             $('.upload_comp_pdf_filename').show();
  2562.            
  2563.             // Name of file and placeholder
  2564.             file = this.files[0].name;
  2565.             dflt = $(this).attr("placeholder");
  2566.            
  2567.             if ($(this).val() != "") {
  2568.                 $(this).siblings('.upload_comp_pdf_filename').text(file);
  2569.             } else {
  2570.                 $(this).siblings('.upload_comp_pdf_filename').text('');
  2571.             }
  2572.         });
  2573.        
  2574.         // Product pdf populate filename
  2575.         $("#upload_prod_pdf_button").on("change", function () {
  2576.            
  2577.             // Show filename and remove fields
  2578.             $('.upload_prod_pdf_filename').show();
  2579.            
  2580.             // Name of file and placeholder
  2581.             file = this.files[0].name;
  2582.             dflt = $(this).attr("placeholder");
  2583.            
  2584.             if ($(this).val() != "") {
  2585.                 $(this).siblings('.upload_prod_pdf_filename').text(file);
  2586.             } else {
  2587.                 $(this).siblings('.upload_prod_pdf_filename').text('');
  2588.             }
  2589.         });
  2590.        
  2591.         // Upload guidance
  2592.         $('#save_pdf_guidance').click(function() {
  2593.            
  2594.             // Block page
  2595.             $.blockUI({message: 'Please wait while files are checked and uploaded...'});
  2596.            
  2597.             // Check if no files are set
  2598.             var comp_file = $('#upload_comp_pdf_button').val();
  2599.             var prod_file = $('#upload_prod_pdf_button').val();
  2600.            
  2601.             if(comp_file == '' && prod_file == '') {
  2602.                
  2603.                 $.alert({
  2604.                     title: 'No Files to Upload',
  2605.                     content: 'Please select a company or product pdf to upload.',
  2606.                     columnClass: 'col-md-6 col-md-offset-3',
  2607.                     confirmButtonClass: 'btn-danger'
  2608.                 });
  2609.                    
  2610.                 // Unblock page
  2611.                 $.unblockUI();
  2612.                    
  2613.                 return false;
  2614.             }
  2615.            
  2616.             // Send the formData
  2617.             var formData = new FormData( $("#upload_pdf_guidance")[0] );
  2618.    
  2619.             $.ajax({
  2620.                 url : '<?php echo base_url() . index_page(); ?>admin/save_guidance_pdf',
  2621.                 type : 'POST',
  2622.                 data : formData,
  2623.                 cache : false,
  2624.                 contentType : false,
  2625.                 processData : false,
  2626.                 success : function(data) {
  2627.                    
  2628.                     // Unblock page
  2629.                     $.unblockUI();
  2630.                    
  2631.                     if(data == 'success') {
  2632.                        
  2633.                         // Alert user data fields updated
  2634.                         $.alert({
  2635.                             title: 'Guidance Uploaded',
  2636.                             content: 'The guidance pdfs were updated successfully.',
  2637.                             columnClass: 'col-md-6 col-md-offset-3',
  2638.                             confirmButtonClass: 'btn-info'
  2639.                         });
  2640.                     }
  2641.                     else {
  2642.                        
  2643.                         // Alert user data fields update failed
  2644.                         $.alert({
  2645.                             title: 'Guidance Upload Failed',
  2646.                             content: 'An error was encountered while updating the guidance pdfs.<br />' + data + '<br /><br />Please contact a system administrator if assistance is needed.',
  2647.                             columnClass: 'col-md-6 col-md-offset-3',
  2648.                             confirmButtonClass: 'btn-danger'
  2649.                         });
  2650.                     }
  2651.                 }
  2652.             });
  2653.         });
  2654.        
  2655.         // Remove company pdf
  2656.         $('.remove_comp_pdf').click(function() {
  2657.            
  2658.             // Confirm delete company pdf
  2659.             $.confirm({
  2660.                 title: 'Delete Company PDF',
  2661.                 content: 'The company .pdf file will be removed.',
  2662.                 columnClass: 'col-md-6 col-md-offset-3',
  2663.                 confirmButtonClass: 'btn-info',
  2664.                 cancelButtonClass: 'btn-danger',
  2665.                 confirmButton: 'Delete PDF',
  2666.                 confirm: function() {
  2667.                    
  2668.                     // Fire ajax to update options
  2669.                     $.post("<?php echo base_url() . index_page(); ?>admin/delete_company_pdf").done(function(data) {
  2670.                        
  2671.                         if(data == 'success') {
  2672.                            
  2673.                             // Alert pdf removed successfully
  2674.                             $.alert({
  2675.                                 title: 'Guidance PDF Deleted',
  2676.                                 content: 'The guidance pdf was deleted successfully.',
  2677.                                 columnClass: 'col-md-6 col-md-offset-3',
  2678.                                 confirmButtonClass: 'btn-info'
  2679.                             });
  2680.                            
  2681.                             // Clear filename and remove fields
  2682.                             $('.upload_comp_pdf_filename').hide();
  2683.                             $('.remove_comp_pdf').hide();
  2684.                         }
  2685.                         else {
  2686.                            
  2687.                             // Alert pdf removal failed
  2688.                             $.alert({
  2689.                                 title: 'Guidance PDF Deletion Failed',
  2690.                                 content: 'An error was encountered while deleting the company guidance PDF. Please contact a system administrator.',
  2691.                                 columnClass: 'col-md-6 col-md-offset-3',
  2692.                                 confirmButtonClass: 'btn-danger'
  2693.                             });
  2694.                         }
  2695.                     });
  2696.                 }
  2697.             });
  2698.         });
  2699.        
  2700.         // Remove product pdf
  2701.         $('.remove_prod_pdf').click(function() {
  2702.            
  2703.             // Confirm delete product pdf
  2704.             $.confirm({
  2705.                 title: 'Delete Product PDF',
  2706.                 content: 'The product .pdf file will be removed.',
  2707.                 columnClass: 'col-md-6 col-md-offset-3',
  2708.                 confirmButtonClass: 'btn-info',
  2709.                 cancelButtonClass: 'btn-danger',
  2710.                 confirmButton: 'Delete PDF',
  2711.                 confirm: function() {
  2712.                    
  2713.                     // Fire ajax to update options
  2714.                     $.post("<?php echo base_url() . index_page(); ?>admin/delete_product_pdf").done(function(data) {
  2715.                        
  2716.                         if(data == 'success') {
  2717.                            
  2718.                             // Alert pdf removed successfully
  2719.                             $.alert({
  2720.                                 title: 'Guidance PDF Deleted',
  2721.                                 content: 'The guidance pdf was deleted successfully.',
  2722.                                 columnClass: 'col-md-6 col-md-offset-3',
  2723.                                 confirmButtonClass: 'btn-info'
  2724.                             });
  2725.                            
  2726.                             // Clear filename and remove fields
  2727.                             $('.upload_prod_pdf_filename').hide();
  2728.                             $('.remove_prod_pdf').hide();
  2729.                         }
  2730.                         else {
  2731.                            
  2732.                             // Alert pdf removal failed
  2733.                             $.alert({
  2734.                                 title: 'Guidance PDF Deletion Failed',
  2735.                                 content: 'An error was encountered while deleting the product guidance PDF. Please contact a system administrator.',
  2736.                                 columnClass: 'col-md-6 col-md-offset-3',
  2737.                                 confirmButtonClass: 'btn-danger'
  2738.                             });
  2739.                         }
  2740.                     });
  2741.                 }
  2742.             });
  2743.         });
  2744.        
  2745.         var $comp_id_name_chart_table = $('table#comp_id_name_chart_table');
  2746.        
  2747.         // Toggle company name/id reference chart
  2748.         $('#comp_id_name_chart').click(function() {
  2749.            
  2750.             // Toggle table div
  2751.             $('#comp_id_name_chart_div').toggle();
  2752.            
  2753.             // Adjust class to keep active
  2754.             if($(this).hasClass('reference_active')) {
  2755.                 $(this).removeClass('reference_active');
  2756.             }
  2757.             else {
  2758.                 $(this).addClass('reference_active');
  2759.             }
  2760.         });
  2761.        
  2762.         // Set sortable table for company chart
  2763.         $("table#comp_id_name_chart_table").tablesorter({headers: { 0: { filter: true, sorter: true} }, widthFixed: true, widgets: ['filter', 'output'], widgetOptions: {
  2764.             filter_defaultFilter: { 1: '~{query}' },
  2765.             filter_columnFilters: true,
  2766.             filter_placeholder: { search: 'Search...' },
  2767.             filter_saveFilters: true,
  2768.             filter_reset: '.reset',
  2769.             output_delivery: 'd',
  2770.             output_saveFileName: 'Company_Name_ID_Reference_Chart.csv'
  2771.         }});
  2772.        
  2773.         // Download comp name/id to csv
  2774.         $('.comp_id_name_chart_to_csv').click(function(){
  2775.            
  2776.             // Tell the output widget do it's thing
  2777.             $comp_id_name_chart_table.trigger('outputTable');
  2778.         });
  2779.        
  2780.         var $prod_id_name_chart_table = $('table#prod_id_name_chart_table');
  2781.        
  2782.         // Toggle product name/id reference chart
  2783.         $('#prod_id_name_chart').click(function() {
  2784.            
  2785.             // Toggle table div
  2786.             $('#prod_id_name_chart_div').toggle();
  2787.            
  2788.             // Adjust class to keep active
  2789.             if($(this).hasClass('reference_active')) {
  2790.                 $(this).removeClass('reference_active');
  2791.             }
  2792.             else {
  2793.                 $(this).addClass('reference_active');
  2794.             }
  2795.         });
  2796.        
  2797.         // Set sortable table for product chart
  2798.         $("table#prod_id_name_chart_table").tablesorter({headers: { 0: { filter: true, sorter: true} }, widthFixed: true, widgets: ['filter', 'output'], widgetOptions: {
  2799.             filter_defaultFilter: { 1: '~{query}' },
  2800.             filter_columnFilters: true,
  2801.             filter_placeholder: { search: 'Search...' },
  2802.             filter_saveFilters: true,
  2803.             filter_reset: '.reset',
  2804.             output_delivery: 'd',
  2805.             output_saveFileName: 'Product_Name_ID_Reference_Chart.csv'
  2806.         }});
  2807.        
  2808.         // Download prod name/id to csv
  2809.         $('.prod_id_name_chart_to_csv').click(function(){
  2810.            
  2811.             // Tell the output widget do it's thing
  2812.             $prod_id_name_chart_table.trigger('outputTable');
  2813.         });
  2814.        
  2815.         var $prod_fam_id_name_chart_to_csv = $('table#prod_fam_id_name_chart_table');
  2816.        
  2817.         // Toggle product family/id reference chart
  2818.         $('#prod_fam_id_name_chart').click(function() {
  2819.            
  2820.             // Toggle table div
  2821.             $('#prod_fam_id_name_chart_div').toggle();
  2822.            
  2823.             // Adjust class to keep active
  2824.             if($(this).hasClass('reference_active')) {
  2825.                 $(this).removeClass('reference_active');
  2826.             }
  2827.             else {
  2828.                 $(this).addClass('reference_active');
  2829.             }
  2830.         });
  2831.        
  2832.         // Set sortable table for product family chart
  2833.         $("table#prod_fam_id_name_chart_table").tablesorter({headers: { 0: { filter: true, sorter: true} }, widthFixed: true, widgets: ['filter', 'output'], widgetOptions: {
  2834.             filter_defaultFilter: { 1: '~{query}' },
  2835.             filter_columnFilters: true,
  2836.             filter_placeholder: { search: 'Search...' },
  2837.             filter_saveFilters: true,
  2838.             filter_reset: '.reset',
  2839.             output_delivery: 'd',
  2840.             output_saveFileName: 'Product_Family_ID_Reference_Chart.csv'
  2841.         }});
  2842.        
  2843.         // Download prod fam/id to csv
  2844.         $('.prod_fam_id_name_chart_to_csv').click(function(){
  2845.            
  2846.             // Tell the output widget do it's thing
  2847.             $prod_fam_id_name_chart_to_csv.trigger('outputTable');
  2848.         });
  2849.        
  2850.        
  2851.         // Toggle search logs div
  2852.         $('#show_search_logs').click(function() {
  2853.            
  2854.             $('.search_logs_div').toggle();
  2855.         });
  2856.        
  2857.         // Set sortable table for search logs
  2858.         $("table#search_logs_table").tablesorter({headers: { 0: { filter: true, sorter: true} }, widthFixed: true, widgets: ['filter', 'output'], widgetOptions: {
  2859.             filter_defaultFilter: { 1: '~{query}' },
  2860.             filter_columnFilters: true,
  2861.             filter_placeholder: { search: 'Search...' },
  2862.             filter_saveFilters: true,
  2863.             filter_reset: '.reset',
  2864.             output_delivery: 'd',
  2865.             output_saveFileName: 'Search_Log.csv'
  2866.         }});
  2867.     });
  2868. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement