Advertisement
plirof2

tabulator timetable program v220909 - added combo info

Sep 10th, 2022 (edited)
1,509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 23.27 KB | None | 0 0
  1. <?php
  2. /*
  3. index.php
  4. changes:
  5. -220909 -  Trying to show remainign hours v001
  6.  
  7. ToDo / Bugs:
  8. -220909 - [seemed Fixed] Export/Import broken
  9.  
  10.  
  11. */
  12.  
  13. //print_r($_POST)    ;
  14.  
  15. $posted_data=false; //if true we will fill all cells with ready data
  16.  
  17. $teacherlist_text= "Α1-ΔΑΣΚΑΛΟΣ1,24\nΑ2-ΔΑΣΚΑΛΟΣ2,20\nΒ1-ΔΑΣΚΑΛΟΣ3,20\nΒ2-ΔΑΣΚΑΛΟΣ4,20\nΓ1-ΔΑΣΚΑΛΟΣ5,20\nΓ2-ΔΑΣΚΑΛΟΣ6,20\nΔ1-ΔΑΣΚΑΛΟΣ7,20\nΔ2-ΔΑΣΚΑΛΟΣ8,20\nΕ1-ΔΑΣΚΑΛΟΣ9,20\nΕ2-ΔΑΣΚΑΛΟΣ10,20\nΣΤ1-ΔΑΣΚΑΛΟΣ11,20\nΣΤ2-ΔΑΣΚΑΛΟΣ12,20\nΠΛΗΡ,11,cyan\nΓΥΜΝ1,11,yellow\nΑΓΓΛ,11,green\nΓΕΡΜ,4,grey\nΓΑΛ,4,purple\n";
  18. $tmimatalist_text="Α1,Α2,Β1,Β2,Γ1,Γ2,Δ1,Δ2,Ε1,Ε2,ΣΤ1,ΣΤ2";
  19.  
  20. include "include_posted_variables.php";
  21.  
  22. /*  
  23. if(@($_POST['timetable_teacher'] )) {
  24.     $teacherlist_text=$_POST['timetable_teacher'];
  25.     $posted_data=true;
  26. }
  27.  
  28. if(@($_POST['timetable_tmimata'] )) {
  29.     $tmimatalist_text=$_POST['timetable_tmimata'];
  30.     $posted_data=true;
  31. }
  32.  
  33. $program_data="";  //not impemented yet
  34. if(@($_POST['timetable_program'] )) {
  35.     $program_data=$_POST['timetable_program'];
  36.     $posted_data=true;
  37. }
  38. */    
  39. $tmimata_array = explode(',',$tmimatalist_text);
  40.  
  41.  
  42.  
  43. ?>
  44. <html>
  45. <head>
  46. <script type="text/javascript" src="js/jquery1.12.4.js"></script>
  47. <script type="text/javascript" src="js/jquery-ui.min.js"></script> 
  48. <script type="text/javascript" src="js/jquery.ui.touch-punch.min.js"></script>
  49. <!--<script type="text/javascript" src="http://oss.sheetjs.com/js-xlsx/xlsx.full.min.js"></script> -->
  50. <script type="text/javascript" src="js/js-xlsx/xlsx.full.min.js"></script>
  51. <link   href="css/tabulator353/tabulator.min.css" rel="stylesheet">
  52. <!--<link href="css/tabulator.min.css" rel="stylesheet"> -->
  53. <script type="text/javascript" src="js/tabulator353/tabulator.min.js"></script>
  54. <!--<script type="text/javascript" src="js/tabulator.min.js"></script>-->
  55.  
  56.        
  57. <!--<script src="js/selectize-standalone/selectize.min.js"></script> -->
  58.  
  59.  
  60. </head>
  61. <body>
  62.  
  63. <table><tr><td>
  64. <form method="post" >
  65.     ΕΚΠΑΙΔΕΥΤΙΚΟΙ (Ένας σε κάθε σειρά):<BR> <textarea id="teacherslist" name='timetable_teacher' cols=50 rows=10 ><?php echo $teacherlist_text; ?></textarea><BR><BR><BR><BR>
  66.     </td><td>
  67.        
  68.     TMHMATA (χωρισμένα με κόμμα):<BR><textarea id="tmimatalist" name='timetable_tmimata' cols=50 rows=10 ><?php echo $tmimatalist_text; ?></textarea>
  69. <input type=submit value="ΚΑΤΑΧΩΡΗΣΗ ΤΜΗΜΑΤΩΝ"> (ΠΡΟΣΟΧΗ!!! Θα διαγραφεί το πρόγραμμα)
  70. </form>    
  71.     </td></tr>
  72. </table>
  73.  
  74.  
  75.  
  76. <hr size=10 color=lightgrey>
  77.  
  78. <!-- <button id="download-json">download-json</button> -->
  79. <button id="download-xlsx">Εξαγωγή σε excel</button>
  80. <button id="auto_assign_first_teachers">Αρχική κατανομή δασκαλών</button>
  81. <button id="btn-save-all-data">Πλήρες αντίγραφό (αποθήκευση)</button>
  82. <button id="count-teacher-hours">count-teacher-hours</button>
  83. <button id="test-button">TEsT stuff button</button>
  84. <hr size=10 color=lightgrey>
  85. <div id="example-table"></div>
  86. <script>
  87. var posted_data=false;
  88. <?php     if( $posted_data==true) echo "posted_data=true;"; ?>
  89.  
  90. //$("#example-table").tabulator();
  91. var arrayOfTeachers = $('#teacherslist').val().split('\n');
  92. //var table = new Tabulator("#example-table", {});
  93.  
  94. //Note Formatter is only visual , MUTATOR is stored
  95. var colorFormatter = function(cell, formatterParams){
  96.     var value = cell.getValue();
  97.     if(value  == "-"){
  98.        cell.getElement().css("background-color","lightgrey");
  99.        return value;
  100.     }else{
  101.         return value;
  102.     }
  103. };
  104.  
  105. var countTeachersHours_json = function(){
  106.  
  107.     //table.setData($('textarea#programdata').val()); //tabulator v4
  108.     var mytabledata_json =$("#example-table").tabulator("getData"); //tabulator v3
  109.     var json=mytabledata_json;
  110.     var obj = {};
  111.  
  112.     //FIXED counter for up to 16 tmimata
  113.     for (var i = 0, j = json.length; i < j; i++) {
  114.       if (obj[json[i].tmimacode0]) {obj[json[i].tmimacode0]++;}else {obj[json[i].tmimacode0] = 1;}
  115.  
  116.       if (obj[json[i].tmimacode1]) {obj[json[i].tmimacode1]++;}else {obj[json[i].tmimacode1] = 1;}
  117.       if (obj[json[i].tmimacode2]) {obj[json[i].tmimacode2]++;}else {obj[json[i].tmimacode2] = 1;}
  118.       if (obj[json[i].tmimacode3]) {obj[json[i].tmimacode3]++;}else {obj[json[i].tmimacode3] = 1;}
  119.       if (obj[json[i].tmimacode4]) {obj[json[i].tmimacode4]++;}else {obj[json[i].tmimacode4] = 1;}
  120.       if (obj[json[i].tmimacode5]) {obj[json[i].tmimacode5]++;}else {obj[json[i].tmimacode5] = 1;}
  121.       if (obj[json[i].tmimacode6]) {obj[json[i].tmimacode6]++;}else {obj[json[i].tmimacode6] = 1;}
  122.       if (obj[json[i].tmimacode7]) {obj[json[i].tmimacode7]++;}else {obj[json[i].tmimacode7] = 1;}
  123.       if (obj[json[i].tmimacode8]) {obj[json[i].tmimacode8]++;}else {obj[json[i].tmimacode8] = 1;}
  124.       if (obj[json[i].tmimacode9]) {obj[json[i].tmimacode9]++;}else {obj[json[i].tmimacode9] = 1;}
  125.  
  126.       if (obj[json[i].tmimacode10]) {obj[json[i].tmimacode10]++;}else {obj[json[i].tmimacode10] = 1;}
  127.       if (obj[json[i].tmimacode11]) {obj[json[i].tmimacode11]++;}else {obj[json[i].tmimacode11] = 1;}
  128.       if (obj[json[i].tmimacode12]) {obj[json[i].tmimacode12]++;}else {obj[json[i].tmimacode12] = 1;}
  129.       if (obj[json[i].tmimacode13]) {obj[json[i].tmimacode13]++;}else {obj[json[i].tmimacode13] = 1;}
  130.       if (obj[json[i].tmimacode14]) {obj[json[i].tmimacode13]++;}else {obj[json[i].tmimacode14] = 1;}
  131.       if (obj[json[i].tmimacode15]) {obj[json[i].tmimacode13]++;}else {obj[json[i].tmimacode15] = 1;}            
  132.     }
  133.  
  134.     console.log(obj);
  135.     //console.log(Object.values(obj));
  136.     //console.log(Object.keys(obj));
  137.  
  138.     return obj;
  139. };
  140.  
  141. function auto_assined_teacher_table(){
  142.     var counter_row_whole_table=1;
  143.     var counter_tmima_col=0;
  144.     //$array_of_teachers_php=explode(PHP_EOL, $teacherlist_text);
  145.  
  146.     //var get_teachers_textarea = $('#teacherslist').val();
  147.     var arrayOfTeachers = $('#teacherslist').val().split('\n');
  148.     //var get_tmimata_textarea = $('#tmimatalist').val();
  149.     var tmimata_array = $('#tmimatalist').val().split(',');
  150.     var tmimata_arrayLength = tmimata_array.length;
  151.     //console.log("tmimata length="+tmimata_arrayLength)
  152.     // day 1
  153.     var days_array=["ΔΕΥΤΕΡΑ","ΤΡΙΤΗ","ΤΕΤΑΡΤΗ","ΠΕΜΠΤΗ","ΠΑΡΑΣΚΕΥΗ"];
  154.     var timetable_json="[";
  155.     var timetable_row="";
  156.  
  157.     for( var i=1;i<=5;i++) { //Loop through 5 days of week
  158.         /*
  159.         echo '{id:'.$counter_row_whole_table.',time:"'.$this_day.'"},';
  160.         $counter_row_whole_table++;
  161.         */
  162.         //put teachers to first 4 hours
  163.         for(var daily_hour_counter=1;daily_hour_counter<5;daily_hour_counter++){
  164.             timetable_row= '{"id":'+counter_row_whole_table+',"day":"'+days_array[i-1]+'","time":"'+daily_hour_counter+'",';    
  165.             counter_tmima_col=0;
  166.             //foreach(tmimata_array as $tmima) {
  167.             for( var j=0;j<tmimata_arrayLength;j++) {
  168.                 var teacher_row_data=arrayOfTeachers[counter_tmima_col].split(','); // get the name of the chosen teacher
  169.                 var teacher_name=teacher_row_data[0];  
  170.                 //timetable_row+= '"tmimacode'+counter_tmima_col+'":"'+arrayOfTeachers[counter_tmima_col]+'"';
  171.                 timetable_row+= '"tmimacode'+counter_tmima_col+'":"'+teacher_name+'"';
  172.                 if(j<(tmimata_arrayLength-1))timetable_row+=',';
  173.                 counter_tmima_col++;
  174.             }
  175.            
  176.             counter_row_whole_table++;
  177.             timetable_row+='}';
  178.             if(!(daily_hour_counter==4 && i==5))timetable_row+=',';
  179.             timetable_json+=timetable_row;
  180.         } //end of for($daily_hour_counter=1
  181.          //timetable_row+=',';
  182.          counter_row_whole_table+=6;
  183.     }
  184.     timetable_json+=']';
  185.     //console.log(timetable_json)   ;
  186.     return timetable_json;
  187. }
  188.  
  189.  
  190. function split_remaining_hours(combo_name){
  191.     //This will seperate the visible combo value (name+remaining hours) so we return ONLY the name -without hours
  192.     var array = combo_name.split('[');
  193.  
  194.     return array[0];
  195. }
  196.  
  197.  
  198. var cellEditSelectTeacherFunction=function(cell){
  199.  
  200.     var count_teacher_hours_object=countTeacherHours();
  201.     var cellValue = cell.getValue();
  202.     //console.log(cell);
  203.  
  204.     //create a options list of all names currently in the table
  205.     var arrayOfTeachers = $('#teacherslist').val().split('\n');
  206.     var arrayOfTeachers2 = {};
  207.  
  208.     arrayOfTeachers.forEach(function(row){
  209.         var data = row;
  210.         //alert(data);
  211.         //console.log(data);
  212.  
  213.        
  214.  
  215.         var teacher_row_data=data.split(',');
  216.         var teacher_name=teacher_row_data[0];
  217.         var teacher_max_hours=teacher_row_data[1];
  218.  
  219.         //calculated vars :
  220.         var remaining_hours_of_teacher=teacher_max_hours-count_teacher_hours_object[teacher_name];
  221.         if (isNaN(parseFloat(remaining_hours_of_teacher)) ) remaining_hours_of_teacher=teacher_max_hours;
  222.         var combo_teacher_display_text=teacher_name+"["+remaining_hours_of_teacher+']';
  223.         //var combo_teacher_display_text=teacher_name+"[<font color=red> "+remaining_hours_of_teacher+'</font>]';
  224.  
  225.         if (teacher_name.length<2) return; //jon 220909 - maybe merge with the if exceed max hours
  226.  
  227.  
  228.         //console.log(teacher_name ,count_teacher_hours_object[teacher_name],'remain:',teacher_max_hours-count_teacher_hours_object[teacher_name]);
  229.         //console.log("\n",'HELLOOOOOOOOO',combo_teacher_display_text," :" ,split_remaining_hours(teacher_name+"[10]"));
  230.         //console.log(count_teacher_hours_object[teacher_name]);
  231.  
  232.         //console.log(teacher_row_data[0]);
  233.         //console.log(count_teacher_hours_object[teacher_name]);
  234.         if(count_teacher_hours_object[teacher_name]>=teacher_max_hours && cellValue!=teacher_name) return; //skip this iteration if teacher exceeded his hours
  235.         //arrayOfTeachers2[data] = data;
  236.         //arrayOfTeachers2[teacher_name] = teacher_name; // Combo Box Value  ORIGINAL (THIS WORKS)
  237.         arrayOfTeachers2[teacher_name] = combo_teacher_display_text; // jon TEST 220909 Combo Box Value
  238.     });
  239.     arrayOfTeachers2['-'] ='--';
  240.     return arrayOfTeachers2;
  241.    
  242.  
  243.     //var rows = $("example-table").tabulator("getRows");
  244.     /*
  245.     var options = {};
  246.     options["ΠΛΗΡ"]="ΠΛΗΡΟΦΟΡΙΚΗ";
  247.     options["Α"]="Α";
  248.     options["Β1"]="Β1";
  249.     options["Γ1"]="Γ1";
  250.     options["Δ1"]="Δ1";
  251.     options["ΜΟΥΣ"]="ΜΟΥΣΙΚΗ";
  252.     return options;
  253.     */
  254. }; // end of var cellEditSelectTeacherFunction
  255.  
  256. /* alert ("<?php echo $program_data;?>"); */
  257. var tableData =
  258.    
  259.     <?php
  260.  
  261.     if($posted_data) {
  262.         echo $program_data;
  263.     }else
  264.     {
  265.     echo"[";
  266.     $counter_row_whole_table=1;
  267.     // day 1
  268.     $days_array=["ΔΕΥΤΕΡΑ","ΤΡΙΤΗ","ΤΕΤΑΡΤΗ","ΠΕΜΠΤΗ","ΠΑΡΑΣΚΕΥΗ"];
  269.     foreach($days_array as $this_day) {
  270.         /*
  271.         echo '{id:'.$counter_row_whole_table.',time:"'.$this_day.'"},';
  272.         $counter_row_whole_table++;
  273.         */
  274.         for($daily_hour_counter=1;$daily_hour_counter<11;$daily_hour_counter++){
  275.             $timetable_row= '{id:'.$counter_row_whole_table.',day:"'.$this_day.'",time:"'.$daily_hour_counter.'",';    
  276.             $counter_tmima_col=0;
  277.             foreach($tmimata_array as $tmima) {
  278.                 $timetable_row.= 'tmimacode'.$counter_tmima_col.':"-",';
  279.                 $counter_tmima_col++;
  280.             }
  281.            
  282.             $counter_row_whole_table++;
  283.             $timetable_row.='},';
  284.             echo $timetable_row;
  285.         } //end of for($daily_hour_counter=1
  286.     }
  287.     echo"]";
  288.     }
  289.     ?>
  290.  
  291.  
  292.  
  293.  
  294. //var table = new Tabulator("#example-table", { // tabulator v4
  295. $("#example-table").tabulator( {     //tabulator v3
  296.     data:tableData, //set initial table data
  297.     //eight:"311px",
  298.     //layout:"fitDataFill",
  299.     groupBy:"day",
  300.     layout:"fitColumns",
  301.     //movableRows:true,
  302.         columns:[
  303.         {title:"ΗΜΕΡΑ", field:"day",headerSort:false,visible:false ,hideInHtml:false, editor:false},
  304.         {title:"ΩΡΑ", field:"time",headerSort:false, editor:false},
  305.     <?php                
  306.         $counter_tmima_col=0;
  307.         foreach($tmimata_array as $tmima) {
  308.             echo '{title:"'.$tmima.'", field:"tmimacode'.$counter_tmima_col.'",headerSort:false, editor:"select",formatter:colorFormatter, editorParams:cellEditSelectTeacherFunction
  309.            },';
  310.             $counter_tmima_col++;
  311.         }
  312.        
  313.     ?>
  314.            
  315.     ],
  316.  
  317.     rowFormatter:function(row){
  318.         //row - row component
  319.         var data = row.getData();
  320.         //console.log(data.tmimacode0);
  321.         if(data.col == "ΠΛΗΡ,11" ){
  322.            // alert(data.tmimacode0);
  323.             //row.getElement().css({"background-color":"cyan"});
  324.         }
  325.     },
  326.  
  327.     // INTERCEPT download maybe used to make a bigger JSON to contain more teachers& classes
  328.     downloadReady:function(fileContents, blob){
  329.         //fileContents - the unencoded contents of the file
  330.         //blob - the blob object for the download
  331.         //alert(blob);
  332.         //custom action to send blob to server could be included here
  333.         return blob; //must return a blob to proceed with the download, return false to abort download
  334.     },
  335.  
  336.     validationFailed:function(cell, value, validators){
  337.         //cell - cell component for the edited cell
  338.         //value - the value that failed validation
  339.         //validatiors - an array of validator objects that failed
  340.  
  341.         //take action on validation fail
  342.     },
  343.     rowMoved:function(row){
  344.         alert("Row: " + row.getData().name + " has been moved");
  345.     },
  346.     rowClick:function(e, row){
  347.        // alert("Row " + row.getIndex() + " Clicked!!!!")
  348.     },
  349.     rowContext:function(e, row){
  350.         alert("Row " + row.getIndex() + " Context Clicked!!!!")
  351.     },    
  352. }); // END Of tabulator Init
  353.  
  354. /* if(posted_data && (typeof program_data !== 'undefined') ) $("#example-table").tabulator("setData","<?php print_r($program_data); echo $program_data; ?>"); //tabulator v3  */
  355.  
  356.  
  357. //$("#example-table").tabulator("download", "xlsx", "data.xlsx", {sheetName:"MyData"}); //download a Xlsx file that has a sheet name of "MyData"
  358.  
  359.  
  360. //trigger download of data.xlsx file
  361. $("#download-xlsx").click(function(){
  362.     /*
  363.     // +++++++++tab v4++++++++++++
  364.     table.showColumn("day"); //show the "name" column
  365.     table.download("xlsx", "school_program.xlsx", {sheetName:"My Data"});
  366.     table.hideColumn("day"); //show the "name" column
  367.     */
  368.     // +++++++++tab v3++++++++++++
  369.     $("#example-table").tabulator("showColumn","day");
  370.     $("#example-table").tabulator("download", "xlsx", "school_program.xlsx", {sheetName:"MyData"}); //download a Xlsx file that has a sheet name of "MyData"
  371.     $("#example-table").tabulator("hideColumn","day");
  372. });
  373.  
  374. //trigger download of data.xlsx file
  375. $("#auto_assign_first_teachers").click(function(){
  376.  
  377.     //var arrayOfTeachers = $('#teacherslist').val().split('\n');
  378.  
  379.  
  380.     //console.log(auto_assined_teacher_table());
  381.     //var jsontext = '{"firstname":"Jesper","surname":"Aaberg","phone":["555-0100","555-0120"]}';
  382.     //var auto_assined_teacher_table = JSON.parse(jsontext);
  383.     //$("#example-table").tabulator("updateOrAddData", [{id:1, name:"bob"}, {id:3, name:"steve"}]);
  384.     $("#example-table").tabulator("updateOrAddData",auto_assined_teacher_table()); //tabulator v3
  385. });
  386.  
  387. var json_imported_data = [
  388.     {
  389.         "id": "1",
  390.         "day": "ΔΕΥΤΕΡΑ",
  391.         "time": "1",
  392.         "tmimacode0": "-",
  393.         "tmimacode1": "-",
  394.         "tmimacode2": "-",
  395.         "tmimacode3": "-",
  396.         "tmimacode4": "-",
  397.         "tmimacode5": "-",
  398.         "tmimacode6": "-",
  399.         "tmimacode7": "-",
  400.         "tmimacode8": "-",
  401.         "tmimacode9": "-"
  402.     },
  403.     {
  404.         "id": "2",
  405.         "day": "ΔΕΥΤΕΡΑ",
  406.         "time": "2",
  407.         "tmimacode0": "-",
  408.         "tmimacode1": "-",
  409.         "tmimacode2": "-",
  410.         "tmimacode3": "-",
  411.         "tmimacode4": "-",
  412.         "tmimacode5": "-",
  413.         "tmimacode6": "-",
  414.         "tmimacode7": "-",
  415.         "tmimacode8": "-",
  416.         "tmimacode9": "-"
  417.     } ]        ;
  418.  
  419.  
  420.  
  421. //Add row on "import json" button click
  422. </script>
  423. <hr size=10 color=olive>
  424. <h3>Αποθήκευση/Επαναφορά ΜΟΝΟ πίνακα προγράμματος</h3>
  425. <button id="download-json">download-json</button>
  426. <button id="import_json">import_json</button><BR>
  427. <script type="text/javascript">
  428.  
  429.  
  430. $("#import_json").click(function(){
  431.     //table.setData($('textarea#programdata').val()); //tabulator v4
  432.     $("#example-table").tabulator("setData",$('textarea#programdata').val()); //tabulator v3
  433. });
  434.  
  435. //trigger download of data.json file
  436. $("#download-json").click(function(){
  437.     /*
  438.     // +++++++++tab v4++++++++++++    
  439.     table.showColumn("day"); //show the "name" column
  440.     table.download("json", "data.json");
  441.     table.hideColumn("day"); //show the "name" column
  442.     */
  443.     // +++++++++tab v3++++++++++++
  444.     $("#example-table").tabulator("showColumn","day");
  445.     $("#example-table").tabulator("download", "json", "backup_school_program.json");
  446.     $("#example-table").tabulator("hideColumn","day");
  447. });
  448.  
  449. // ##################   download TOTAL backup file +++++++++++++++
  450.  
  451. var textFile = null,
  452.   makeTextFile = function (text) {
  453.     var data = new Blob([text], {type: 'text/plain'});
  454.  
  455.     // If we are replacing a previously generated file we need to
  456.     // manually revoke the object URL to avoid memory leaks.
  457.     if (textFile !== null) {
  458.       window.URL.revokeObjectURL(textFile);
  459.     }
  460.  
  461.     textFile = window.URL.createObjectURL(data);
  462.  
  463.     return textFile;
  464.   };
  465.  
  466. $("#btn-save-all-data").click(function () {
  467.  
  468.     var get_mytabledata =$("#example-table").tabulator("getData"); //tabulator v3 -OBJECT must make it TEXT
  469.     var myJSON_mytabledata = JSON.stringify(get_mytabledata);
  470.  
  471.     var get_teachers_textarea = $('#teacherslist').val();
  472.     var get_tmimata_textarea = $('#tmimatalist').val();
  473.  
  474.     //var create = document.getElementById('create'),
  475.     //textbox = document.getElementById('textbox');
  476.  
  477.     var d = new Date();
  478.     var link = document.createElement('a');
  479.     link.setAttribute('download', 'school_full_backup'+d.getTime()+'.txt');
  480.     //link.href = makeTextFile(textbox.value);
  481.     link.href = makeTextFile(get_teachers_textarea+'|||||'+get_tmimata_textarea+'|||||'+myJSON_mytabledata);
  482.     document.body.appendChild(link);
  483.  
  484.     // wait for the link to be added to the document
  485.     window.requestAnimationFrame(function () {
  486.       var event = new MouseEvent('click');
  487.       link.dispatchEvent(event);
  488.       document.body.removeChild(link);
  489.         });
  490.    
  491. });
  492.  
  493.  
  494.  
  495. // ##################   download file -----------------
  496.  
  497.  
  498. //
  499. $("#count-teacher-hours").click(function(){
  500.  
  501.  
  502.     return countTeacherHours();
  503.  
  504.  
  505. });
  506.  
  507. //Test button
  508. $("#test-button").click(function(){
  509.     var get_mytabledata =$("#example-table").tabulator("getData");
  510.     console.log(get_mytabledata);
  511.     //var mytabledata_json =$("#example-table").tabulator("getData"); //tabulator v3
  512.     var result_obj=countTeacherHours();
  513.     for (var key in result_obj) {
  514.         console.log("key " + key + " has value " + result_obj[key]);
  515.     }
  516.  
  517.     console.log(result_obj);
  518.     return result_obj;
  519.  
  520. });
  521.  
  522.  
  523.  
  524. var countTeacherHours = function(){
  525.     //table.setData($('textarea#programdata').val()); //tabulator v4
  526.     var mytabledata_json =$("#example-table").tabulator("getData"); //tabulator v3
  527.     //console.log(mytabledata);
  528.     var json=mytabledata_json;
  529.     var obj = {};
  530.     //var tmimata_array = $('#tmimatalist').val().split(',')
  531.     //var counter_tmima_col=0;
  532.     //var arrayLength = tmimata_array.length;
  533.     //console.log(tmimata_array);
  534.     //FIXED counter for up to 16 tmimata
  535.     for (var i = 0, j = json.length; i < j; i++) {
  536.       if (obj[json[i].tmimacode0]) {obj[json[i].tmimacode0]++;}else {obj[json[i].tmimacode0] = 1;}
  537.  
  538.       if (obj[json[i].tmimacode1]) {obj[json[i].tmimacode1]++;}else {obj[json[i].tmimacode1] = 1;}
  539.       if (obj[json[i].tmimacode2]) {obj[json[i].tmimacode2]++;}else {obj[json[i].tmimacode2] = 1;}
  540.       if (obj[json[i].tmimacode3]) {obj[json[i].tmimacode3]++;}else {obj[json[i].tmimacode3] = 1;}
  541.       if (obj[json[i].tmimacode4]) {obj[json[i].tmimacode4]++;}else {obj[json[i].tmimacode4] = 1;}
  542.       if (obj[json[i].tmimacode5]) {obj[json[i].tmimacode5]++;}else {obj[json[i].tmimacode5] = 1;}
  543.       if (obj[json[i].tmimacode6]) {obj[json[i].tmimacode6]++;}else {obj[json[i].tmimacode6] = 1;}
  544.       if (obj[json[i].tmimacode7]) {obj[json[i].tmimacode7]++;}else {obj[json[i].tmimacode7] = 1;}
  545.       if (obj[json[i].tmimacode8]) {obj[json[i].tmimacode8]++;}else {obj[json[i].tmimacode8] = 1;}
  546.       if (obj[json[i].tmimacode9]) {obj[json[i].tmimacode9]++;}else {obj[json[i].tmimacode9] = 1;}
  547.  
  548.       if (obj[json[i].tmimacode10]) {obj[json[i].tmimacode10]++;}else {obj[json[i].tmimacode10] = 1;}
  549.       if (obj[json[i].tmimacode11]) {obj[json[i].tmimacode11]++;}else {obj[json[i].tmimacode11] = 1;}
  550.       if (obj[json[i].tmimacode12]) {obj[json[i].tmimacode12]++;}else {obj[json[i].tmimacode12] = 1;}
  551.       if (obj[json[i].tmimacode13]) {obj[json[i].tmimacode13]++;}else {obj[json[i].tmimacode13] = 1;}
  552.       if (obj[json[i].tmimacode14]) {obj[json[i].tmimacode14]++;}else {obj[json[i].tmimacode14] = 1;}
  553.       if (obj[json[i].tmimacode15]) {obj[json[i].tmimacode15]++;}else {obj[json[i].tmimacode15] = 1;}
  554.       if (obj[json[i].tmimacode16]) {obj[json[i].tmimacode16]++;}else {obj[json[i].tmimacode16] = 1;}
  555.       if (obj[json[i].tmimacode17]) {obj[json[i].tmimacode17]++;}else {obj[json[i].tmimacode17] = 1;}            
  556.  
  557.          /* // this eval() crashes PC ...
  558.             arrayLength=1;
  559.             var i=2;
  560.             //for(var i=0;i<arrayLength;i++) {
  561.               if (eval(`obj[json[i].tmimacode${i}]`)) {
  562.                 (eval(`obj[json[i].tmimacode${i}]`))++;
  563.               }
  564.               else {
  565.                 (eval(`obj[json[i].tmimacode${i}] `))= 1;
  566.               }    
  567.               //counter_tmima_col++
  568.             //}
  569.         */
  570.  
  571.     }
  572.  
  573.     console.log(obj);
  574.     //console.log(Object.values(obj));
  575.     //console.log(Object.keys(obj));   
  576.     return (obj);
  577. };
  578.  
  579.  
  580. /*
  581.  
  582.  
  583. //Delete row on "Delete Row" button click
  584. $("#del-row").click(function(){
  585.     table.deleteRow(1);
  586. });
  587.  
  588. //Clear table on "Empty the table" button click
  589. $("#clear").click(function(){
  590.     table.clearData()
  591. });
  592.  
  593. //Reset table contents on "Reset the table" button click
  594. $("#reset").click(function(){
  595.     table.setData(tabledata);
  596. });
  597. */
  598.  
  599.  
  600. </script>
  601. ΕΙΣΑΓΩΓΗ ΔΕΔΟΜΕΝΩΝ ΠΡΟΓΡΑΜΜΑΤΟΣ που έχουν γίνει με το κουμπι εξαγωγή πίνακα σε JSON (αντιγραψτε τα εδώ):<BR> <textarea id="programdata" name='timetable_program' cols=50 rows=10 ></textarea>
  602. <!-- <button id="import_json">import_json</button> BUTTON DOES NOT WORK HERE-->
  603. <BR>
  604. <hr size=10 color=red>
  605. <BR>
  606. <h2>ΕΠΑΝΑΦΟΡΑ ΠΛΗΡΟΥΣ ΑΝΤΙΓΡΑΦΟΥ ΑΣΦΑΛΕΊΑΣ(κάντε επικόλληση του πλήρους περιεχομένου του αρχείου backup παρακάτω και πατείστε "ΕΠΑΝΑΦΟΡΑ")</h2>
  607.  
  608. <form method="post" >
  609. <textarea id="restorebackup" name='timetable_restorebackup' cols=50 rows=10 ></textarea>
  610. <input type=submit value="ΕΠΑΝΑΦΟΡΑ αντίγραφου ασφαλείας">
  611. </form>
  612.  
  613. <?php
  614.     //my tests
  615.     $options["ΠΛΗΡ"]="ΠΛΗΡ";
  616.     $options["Δ1"]="Δ1";
  617.     //print_r($options);
  618. ?>
  619. </body>
  620.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement