Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Commit

Permalink
Add routine of submitting new contributions to the database
Browse files Browse the repository at this point in the history
Modify ParseSteemLink() and "Add Contribution" form, to pass the original submission date
Add new functions (GetProjectID(), AddContribution()) for the new contribution submission routine
  • Loading branch information
dimitrisp2 committed Oct 26, 2018
1 parent 37faa81 commit d27c2f9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
8 changes: 6 additions & 2 deletions contributions.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,17 @@
$partno = $parselink['part'];
$wordcount = $parselink['words'];
$projectname = $parselink['project'];
$submitdate = $parselink['time'];
} else {
$pagecontent = "<i>Unable to parse the post. Please try again later or fill the details below and press \"Submit\" to continue</i>";
$author = "";
$partno = "";
$wordcount = "";
$projectname = "";
$submitdate = "";
}
//print_r($parselink);
$pagecontent .= "<form action=\"contributions.php?a=processadd\" method=\"post\"><div class=\"form-group row\"><label for=\"author\" class=\"col-4 col-form-label\">Author</label> <div class=\"col-8\"><input id=\"author\" name=\"author\" type=\"text\" aria-describedby=\"authorHelpBlock\" required=\"required\" class=\"form-control here\" value=\"$author\"> <span id=\"authorHelpBlock\" class=\"form-text text-muted\">Steem Username without @</span></div></div><div class=\"form-group row\"><label for=\"partno\" class=\"col-4 col-form-label\">Part Number</label> <div class=\"col-8\"><input id=\"partno\" name=\"partno\" placeholder=\"20\" type=\"text\" required=\"required\" class=\"form-control here\" value=\"$partno\"></div></div><div class=\"form-group row\"><label for=\"wordcount\" class=\"col-4 col-form-label\">Word Count</label> <div class=\"col-8\"><input id=\"wordcount\" name=\"wordcount\" placeholder=\"1251\" type=\"text\" required=\"required\" class=\"form-control here\" value=\"$wordcount\"></div></div><div class=\"form-group row\"><label for=\"projectname\" class=\"col-4 col-form-label\">Project</label> <div class=\"col-8\"><input id=\"projectname\" name=\"projectname\" placeholder=\"ReactOS\" type=\"text\" required=\"required\" class=\"form-control here\" value=\"$projectname\"></div></div> <div class=\"form-group row\"><div class=\"offset-4 col-8\"><button name=\"submit\" type=\"submit\" class=\"btn btn-primary\">Submit</button></div></div><input type=\"hidden\" id=\"steemlink\" name=\"steemlink\" value=\"".$steemlink."\"></form>";
$pagecontent .= "<form action=\"contributions.php?a=processadd\" method=\"post\"><div class=\"form-group row\"><label for=\"author\" class=\"col-4 col-form-label\">Author</label> <div class=\"col-8\"><input id=\"author\" name=\"author\" type=\"text\" aria-describedby=\"authorHelpBlock\" required=\"required\" class=\"form-control here\" value=\"$author\"> <span id=\"authorHelpBlock\" class=\"form-text text-muted\">Steem Username without @</span></div></div><div class=\"form-group row\"><label for=\"partno\" class=\"col-4 col-form-label\">Part Number</label> <div class=\"col-8\"><input id=\"partno\" name=\"partno\" placeholder=\"20\" type=\"text\" required=\"required\" class=\"form-control here\" value=\"$partno\"></div></div><div class=\"form-group row\"><label for=\"wordcount\" class=\"col-4 col-form-label\">Word Count</label> <div class=\"col-8\"><input id=\"wordcount\" name=\"wordcount\" placeholder=\"1251\" type=\"text\" required=\"required\" class=\"form-control here\" value=\"$wordcount\"></div></div><div class=\"form-group row\"><label for=\"projectname\" class=\"col-4 col-form-label\">Project</label> <div class=\"col-8\"><input id=\"projectname\" name=\"projectname\" placeholder=\"ReactOS\" type=\"text\" required=\"required\" class=\"form-control here\" value=\"$projectname\"></div></div> <div class=\"form-group row\"><div class=\"offset-4 col-8\"><button name=\"submit\" type=\"submit\" class=\"btn btn-primary\">Submit</button></div></div><input type=\"hidden\" id=\"steemlink\" name=\"steemlink\" value=\"".$steemlink."\"><input type=\"hidden\" id=\"created\" name=\"created\" value=\"".$submitdate."\"></form>";
} else {
print_r($parselink);
$pagecontent = "The contribution you've tried to submit was not made by a member of the ".$teamname." Team. This contribution couldn't be added to the database. If you believe this is an error, please contact an administrator";
Expand All @@ -75,7 +77,9 @@
}

} else if ($action == "processadd") {
print_r($_POST);
$projectid = GetProjectID($_POST['projectname']);
$userid = GetUserID($_POST['author']);
$pagecontent = AddContribution($projectid, $userid, $_POST['steemlink'], $_POST['created'], $_POST['partno'], $_POST['wordcount']);
} else {

}
Expand Down
43 changes: 42 additions & 1 deletion functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,50 @@ function GetUserID($username) {
}
}

// Get the ID of the project set in $project
function GetProjectID($project) {
$result = mysqli_query($GLOBALS['sqlcon'], "SELECT `id` FROM `projects` WHERE `name` = '" . $project . "'");
if ($result) {
$projectfound = mysqli_num_rows($result);
if ($projectfound == 1) {
$row = mysqli_fetch_assoc($result);
return $row['id'];
} else {
return FALSE;
}
} else {
return "error";
}
}


///////////////////
// CONTRIBUTIONS //
///////////////////

function AddContribution($project, $translator, $link, $created, $partno = NULL, $wordcount = NULL) {
if (is_null($partno)) {
$partno = 0;
}

if (is_null($wordcount)) {
$wordcount = 0;
}

$stmt = mysqli_stmt_init($GLOBALS['sqlcon']);
if (mysqli_stmt_prepare($stmt, 'INSERT INTO `contributions` (`project`, `translator`, `link`, `submit`, `partno`, `wordcount`) VALUES(?, ?, ?, ?, ?, ?)')) {
mysqli_stmt_bind_param($stmt, "iissii", $project, $translator, $link, $created, $partno, $wordcount);
$rvl = mysqli_stmt_execute($stmt);
if ($rvl) {
return "The contribution has been added successfully to the database";
} else {
return "Unable to add the contribution to the database. Please try again";
}
} else {
return "error";
}
}

function GetContributionList($user = NULL, $project = NULL, $from = NULL, $to = NULL, $voted = NULL, $reviewed = NULL, $title = NULL) {
// prepare SQL action if any/all of the arguments are set.
if ((!is_null($user)) || (!is_null($project)) || (!is_null($from)) || (!is_null($to)) || (!is_null($voted)) || (!is_null($reviewed))) {
Expand Down Expand Up @@ -367,7 +407,7 @@ function ParseSteemLink($postdata) {
// Add username to the $details array, as it will be returned with the rest of the data.
$details['author'] = ltrim($postdata['username'], "@");
$url = "https://api.steemjs.com/get_content?author=".$details['author']."&permlink=".$postdata['permlink'];

//echo $url;
$json = file_get_contents($url);
//echo $json;

Expand Down Expand Up @@ -396,6 +436,7 @@ function ParseSteemLink($postdata) {

$details['permlink'] = $postdetails['permlink'];
$details['fulltitle'] = $postdetails['title'];
$details['time'] = $postdetails['created'];
return $details;
} else {
return FALSE;
Expand Down

0 comments on commit d27c2f9

Please sign in to comment.