<commit_before><?php 

date_default_timezone_set('UTC');

// function getProperDateFormat($value)
// {
//     $dateFormatString = 'Y-m-d\TH:i:s.u';
//     $date = date_format($value, $dateFormatString);
//     $date = substr($date, 0, -3) . 'Z';
//     return $date;
// }

require 'vendor/autoload.php';
use Parse\ParseObject;
use Parse\ParseUser;
use Parse\ParseException;
use Parse\ParseClient;
use Parse\ParseSessionStorage;
use Parse\ParseInstallation;
use Parse\ParseQuery;
use Parse\ParsePush;

// Start the session
session_start();

$app_id = "kddcodGlyJ6DmGI7FihXt8BsXyOTS09Dgpj8UA49";
$rest_key = "<KEY>";
$master_key = "Fm9X40ewplSIEDTOmYxVdCEN7ge31vgfFwScYr3y";

ParseClient::initialize( $app_id, $rest_key, $master_key );

if(isset($_SESSION["username"])) {
    if(isset($_POST["message"]) && $_POST["message"] != "" && strlen($_POST["message"]) <= 255 && isset($_POST["inputEmail"]) && $_POST["inputEmail"] != "") {
        $ping = new ParseObject("Pings");
        $ping->set("Title","TLC Helpdesk"); //Auto set, we change later if need be
        $ping->set("Message",$_POST["message"]);
        //$newDate = getProperDateFormat(new DateTime());
        $date = array(
        "__type" => "Date",
        "iso" => date("c")
        ); 
       
        $ping->setAssociativeArray("Date", $date);
        
        try {
            $query = new ParseQuery($class = '_User');
            $query->equalTo("email", $_POST["inputEmail"]);
            $user = $query->first();
            $relation = $ping->getRelation("User");
            $relation->add($user);
            $ping->save();

        } catch (ParseException $ex) {  
            /* Should pass back a cookie with the error $ex->getMessage() */    
            setcookie("modError",$ex->getMessage());
        } catch (Exception $ex) {  
            /* Should pass back a cookie with the error $ex->getMessage() */
            if($ex->getMessage() == "Cannot create a ParseRelationOperation with no objects.") { //I know this is not great, but the php code uses a base exception when throwing this error and not a parse exception.
                setcookie("modError","Email not found");
            }
            else {
                throw $ex;
            }
        }
    }
    else if(strlen($_POST["message"]) > 255) {
        setcookie("modError","Message cannot be more than 255 characters long");
    }
}

header("Location: index.php"); /* Redirect browser */
exit();

?><commit_msg>Fixes to email name being incorrect.<commit_after><?php 

date_default_timezone_set('UTC');

// function getProperDateFormat($value)
// {
//     $dateFormatString = 'Y-m-d\TH:i:s.u';
//     $date = date_format($value, $dateFormatString);
//     $date = substr($date, 0, -3) . 'Z';
//     return $date;
// }

require 'vendor/autoload.php';
use Parse\ParseObject;
use Parse\ParseUser;
use Parse\ParseException;
use Parse\ParseClient;
use Parse\ParseSessionStorage;
use Parse\ParseInstallation;
use Parse\ParseQuery;
use Parse\ParsePush;

// Start the session
session_start();

$app_id = "kddcodGlyJ6DmGI7FihXt8BsXyOTS09Dgpj8UA49";
$rest_key = "<KEY>";
$master_key = "Fm9X40ewplSIEDTOmYxVdCEN7ge31vgfFwScYr3y";

ParseClient::initialize( $app_id, $rest_key, $master_key );

if(isset($_SESSION["username"])) {
    if(isset($_POST["message"]) && $_POST["message"] != "" && strlen($_POST["message"]) <= 255 && isset($_POST["inputEmail"]) && $_POST["inputEmail"] != "") {
        $ping = new ParseObject("Pings");
        $ping->set("Title","TLC Helpdesk"); //Auto set, we change later if need be
        $ping->set("Message",$_POST["message"]);
        //$newDate = getProperDateFormat(new DateTime());
        $date = array(
        "__type" => "Date",
        "iso" => date("c")
        ); 
       
        $ping->setAssociativeArray("Date", $date);
        
        try {
            $query = new ParseQuery($class = '_User');
            $query->equalTo("username", $_POST["inputEmail"]);
            $user = $query->first();
            //print $_POST["inputEmail"]."<br>";
            //print_r($user);
            //print "Made it <br>";
            $relation = $ping->getRelation("User");
            //print "Made it 2<br>";
            //print_r($relation);
            $relation->add($user);
            //print "Made it 3<br>";
            $ping->save();


        } catch (ParseException $ex) {  
            /* Should pass back a cookie with the error $ex->getMessage() */    
            setcookie("modError",$ex->getMessage());
        } catch (Exception $ex) {  
            /* Should pass back a cookie with the error $ex->getMessage() */
            if($ex->getMessage() == "Cannot create a ParseRelationOperation with no objects.") { //I know this is not great, but the php code uses a base exception when throwing this error and not a parse exception.
                //print $ex->getMessage();
                setcookie("modError","Email not found");
            }
            else {
                throw $ex;
            }
        }
    }
    else if(strlen($_POST["message"]) > 255) {
        setcookie("modError","Message cannot be more than 255 characters long");
    }
}

header("Location: index.php"); /* Redirect browser */
exit();

?>
{'fraction_non_alphanumeric': 0.16905992724487842, 'fraction_numerical': 0.010338885697874785, 'mean_word_length': 2.6027586206896554, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 42, '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': '2025056', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1596, 'n_words': 369}