<commit_before><?php
require_once 'header.php';

$connectionObject = connect();
//TODO first create the Event
$event = getLatestEvent($connectionObject);
$_SESSION['eventId'] = $event['id'];
//echo $_SESSION['eventId'];
?>
<head> 
<title>
Create New Event and Activities page
</title>
<script type="text/javascript">

$(document).ready(function ()
{
    // prepare the data
    /* Get contents of Activity table that match Event ID
     * event if there are none.
     */
var thisEvent = <?php echo $_SESSION['eventId'] ?>;

    var data =
    {
        datatype: "json",
        datafields:
        [
            {name: 'activity_id'},
            {name: 'activity_name'},
            {name: 'activity_desc'},
            {name: 'activity_short_code'},
            {name: 'event_id'},
            {name: 'capacity'},
            {name: 'date'},
            {name: 'project_leader'},
            {name: 'open'}
        ],
        url: 'stcg-json-responses.php?fct=getJSONAllActivitiesAtEvent&eventId=<?php echo $_SESSION['eventId'] ?>',
        sortcolumn: 'activity_id',//note rowid order follows activity_id!
        sortdirection: 'asc',
        async: false,
        
////////////// THIS IS THE UPDATE / ADD ROW THAT HAS TO BE CALLED /////////
        updaterow: function (rowid, rowdata, commit) 
        {
            //alert("at start of update function, here is rowid value [" + rowid + "]");
            if ($("#activity_id").val() === "" || $("#activity_id").val() === null)
            //if (rowid === "" || rowid === null)
            {
                var insData = "activity_name=" + rowdata.activity_name + "&activity_desc=" + rowdata.activity_desc + "&activity_short_code=" + rowdata.activity_short_code + "&capacity=" + rowdata.capacity + "&date=" + rowdata.date + "&project_leader=" + rowdata.project_leader + "&open=" + rowdata.open + "&evId=" + thisEvent;  
                //rowdata.open
               
                $.ajax({
                dataType: 'json',    
                url: 'stcg-json-responses.php?fct=insertNewActivityToNewEvent',
                data: insData,
                cache: false,
                success: myCallback,
                error: myCallbackError
                    }); 
            } 
            else
            {
//update table activity

                var data = "activity_id=" + rowdata.activity_id + "&activity_name=" + rowdata.activity_name + "&activity_desc=" + rowdata.activity_desc + "&activity_short_code=" + rowdata.activity_short_code + "&capacity=" + rowdata.capacity + "&date=" + rowdata.date + "&project_leader=" + rowdata.project_leader + "&open=" + rowdata.open;            
            //alert(data);    
                $.ajax({
                   dataType: 'json',
                   url: 'stcg-json-responses.php?fct=updateSelectedActivity&actId=' + rowdata.activity_id,
                   data: data,
                   cache: false,
                   success: myCallback,
                   error: myCallbackError
                   });
            }
        }
    };//end data source
//create the dataAdapter for the Grid
    var adapter = new $.jqx.dataAdapter(data);
    var editrow = -1;//editrow is merely the row num of the selected row
 // initialize jqxGrid
    $("#jqxgrid").jqxGrid(
    {
        width: 1240,
        source: data,
        sortable: true,
        pageable: false,
        editable: false,
        autoheight: true,
        autorowheight: true,
        columns:  
        [
            {text: '#', datafield: 'activity_id', width: 40},
            {text: 'Act. Name', datafield: 'activity_name', width: 260},
            {text: 'Act. Desc', datafield: 'activity_desc', width: 400},
            {text: 'Code', datafield: 'activity_short_code', width: 60},
           /* {text: 'Cap.', datafield: 'capacity', width: 40},*/
            {text: 'Date', datafield: 'date', columntype: 'datetimeinput', width: 100, cellsalign: 'right'},
            {text: 'PL', datafield: 'project_leader', width: 240},
          /*  {text: 'Open', datafield: 'open', width: 40}, */
            {text: 'Edit', datafield: 'Edit', columntype: 'button', cellsrenderer: function () 
                {
                   return "Edit";
                }, buttonclick: function (row) 
                {
               // open the popup window when the user clicks a button.
               //alert("this is the row id being called in edit click of grid construct: " + row);
                    editrow = row;
                    var offset = $("#jqxgrid").offset();
                    $("#editWindow").jqxWindow(
                    { position: { x: parseInt(offset.left) + 60, y: parseInt(offset.top) + 60 } });
               // get the clicked row's data and initialize the input fields.
                    var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow);
                    $("#activity_id").val(dataRecord.activity_id);
                    $("#activity_name").val(dataRecord.activity_name);
                    $("#activity_desc").val(dataRecord.activity_desc);
                    $("#activity_short_code").val(dataRecord.activity_short_code);
                    $("#capacity").val(dataRecord.capacity);
                    $("#date").val(dataRecord.date);
                    $("#project_leader").val(dataRecord.project_leader);
                    $("#open").val(dataRecord.open);

               // show the popup window.
                    $("#editWindow").jqxWindow('open');
                }
            }
        ]  
    });
// initialize the input fields.
    $("#activity_id").jqxInput({ theme: 'classic' });
    $("#activity_name").jqxInput({ theme: 'classic' });
    $("#activity_desc").jqxInput({ theme: 'classic' });
    $("#activity_short_code").jqxInput({ theme: 'classic' });
    $("#capacity").jqxInput({ theme: 'classic' });
    $("#date").jqxInput({ theme: 'classic' });
    $("#project_leader").jqxInput({ theme: 'classic' });
    $("#open").jqxInput({ theme: 'classic' });

    $("#activity_id").width(200);
    $("#activity_id").height(40);
        
    $("#activity_name").width(400);
    $("#activity_name").height(40);
    $("#activity_desc").width(600);
    $("#activity_desc").height(40);
    $("#activity_short_code").width(200);
    $("#activity_short_code").height(40);
    $("#capacity").width(200);<commit_msg>cosmetic<commit_after><?php
require_once 'header.php';

$connectionObject = connect();
//TODO first create the Event
$event = getLatestEvent($connectionObject);
$_SESSION['eventId'] = $event['id'];
//echo $_SESSION['eventId'];
?>
<head> 
<title>
Create New Event and Activities page
</title>
<script type="text/javascript">

$(document).ready(function ()
{
    // prepare the data
    /* Get contents of Activity table that match Event ID
     * event if there are none.
     */
var thisEvent = <?php echo $_SESSION['eventId'] ?>;

    var data =
    {
        datatype: "json",
        datafields:
        [
            {name: 'activity_id'},
            {name: 'activity_name'},
            {name: 'activity_desc'},
            {name: 'activity_short_code'},
            {name: 'event_id'},
            {name: 'capacity'},
            {name: 'date'},
            {name: 'project_leader'},
            {name: 'open'}
        ],
        url: 'stcg-json-responses.php?fct=getJSONAllActivitiesAtEvent&eventId=<?php echo $_SESSION['eventId'] ?>',
        sortcolumn: 'activity_id',//note rowid order follows activity_id!
        sortdirection: 'asc',
        async: false,
        
////////////// THIS IS THE UPDATE / ADD ROW THAT HAS TO BE CALLED /////////
        updaterow: function (rowid, rowdata, commit) 
        {
            //alert("at start of update function, here is rowid value [" + rowid + "]");
            if ($("#activity_id").val() === "" || $("#activity_id").val() === null)
            //if (rowid === "" || rowid === null)
            {
                var insData = "activity_name=" + rowdata.activity_name + "&activity_desc=" + rowdata.activity_desc + "&activity_short_code=" + rowdata.activity_short_code + "&capacity=" + rowdata.capacity + "&date=" + rowdata.date + "&project_leader=" + rowdata.project_leader + "&open=" + rowdata.open + "&evId=" + thisEvent;  
                //rowdata.open
               
                $.ajax({
                dataType: 'json',    
                url: 'stcg-json-responses.php?fct=insertNewActivityToNewEvent',
                data: insData,
                cache: false,
                success: myCallback,
                error: myCallbackError
                    }); 
            } 
            else
            {
//update table activity

                var data = "activity_id=" + rowdata.activity_id + "&activity_name=" + rowdata.activity_name + "&activity_desc=" + rowdata.activity_desc + "&activity_short_code=" + rowdata.activity_short_code + "&capacity=" + rowdata.capacity + "&date=" + rowdata.date + "&project_leader=" + rowdata.project_leader + "&open=" + rowdata.open;            
            //alert(data);    
                $.ajax({
                   dataType: 'json',
                   url: 'stcg-json-responses.php?fct=updateSelectedActivity&actId=' + rowdata.activity_id,
                   data: data,
                   cache: false,
                   success: myCallback,
                   error: myCallbackError
                   });
            }
        }
    };//end data source
//create the dataAdapter for the Grid
    var adapter = new $.jqx.dataAdapter(data);
    var editrow = -1;//editrow is merely the row num of the selected row
 // initialize jqxGrid
    $("#jqxgrid").jqxGrid(
    {
        width: 1240,
        source: data,
        sortable: true,
        pageable: false,
        editable: false,
        autoheight: true,
        autorowheight: true,
        columns:  
        [
            {text: '#', datafield: 'activity_id', width: 40},
            {text: 'Act. Name', datafield: 'activity_name', width: 260},
            {text: 'Act. Desc', datafield: 'activity_desc', width: 400},
            {text: 'Code', datafield: 'activity_short_code', width: 60},
           /* {text: 'Cap.', datafield: 'capacity', width: 40},*/
            {text: 'Date', datafield: 'date', columntype: 'datetimeinput', width: 100, cellsalign: 'right'},
            {text: 'PL', datafield: 'project_leader', width: 240},
          /*  {text: 'Open', datafield: 'open', width: 40}, */
            {text: 'Edit', datafield: 'Edit', columntype: 'button', cellsrenderer: function () 
                {
                   return "Edit";
                }, buttonclick: function (row) 
                {
               // open the popup window when the user clicks a button.
               //alert("this is the row id being called in edit click of grid construct: " + row);
                    editrow = row;
                    var offset = $("#jqxgrid").offset();
                    $("#editWindow").jqxWindow(
                    { position: { x: parseInt(offset.left) + 60, y: parseInt(offset.top) + 60 } });
               // get the clicked row's data and initialize the input fields.
                    var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow);
                    $("#activity_id").val(dataRecord.activity_id);
                    $("#activity_name").val(dataRecord.activity_name);
                    $("#activity_desc").val(dataRecord.activity_desc);
                    $("#activity_short_code").val(dataRecord.activity_short_code);
                    $("#capacity").val(dataRecord.capacity);
                    $("#date").val(dataRecord.date);
                    $("#project_leader").val(dataRecord.project_leader);
                    $("#open").val(dataRecord.open);

               // show the popup window.
                    $("#editWindow").jqxWindow('open');
                }
            }
        ]  
    });//end grid init
// initialize the input fields.
    $("#activity_id").jqxInput({ theme: 'classic' });
    $("#activity_name").jqxInput({ theme: 'classic' });
    $("#activity_desc").jqxInput({ theme: 'classic' });
    $("#activity_short_code").jqxInput({ theme: 'classic' });
    $("#capacity").jqxInput({ theme: 'classic' });
    $("#date").jqxInput({ theme: 'classic' });
    $("#project_leader").jqxInput({ theme: 'classic' });
    $("#open").jqxInput({ theme: 'classic' });

    $("#activity_id").width(200);
    $("#activity_id").height(40);
        
    $("#activity_name").width(400);
    $("#activity_name").height(40);
    $("#activity_desc").width(600);
    $("#activity_desc").height(40);
    $("#activity_short_code").width(200);
    $("#activity_short_code").height(40);
    $("#capacity").width(200);
{'fraction_non_alphanumeric': 0.16225999370475291, 'fraction_numerical': 0.008183821214982689, 'mean_word_length': 2.0108978914949063, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5966520', 'n_tokens_mistral': 3726, 'n_tokens_neox': 3542, 'n_words': 802}