Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Worked on the File Saving system #17

Merged
merged 2 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions projects/get_project.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

//will contain code to select from this table and more SQL Actions

function get_projects_details($id){
require "../the_connector/connect_area.php";
function get_projects_details($connect, $id){
//require "../the_connector/connect_area.php";
$stmt = $connect->prepare("SELECT * FROM `projects` WHERE `projects_id`=?;");
$stmt->bind_param("i", $id);
$stmt->execute();
Expand All @@ -19,8 +19,8 @@ function get_projects_details($id){
}


function get_projects_details_by_name($name){
require "../the_connector/connect_area.php";
function get_projects_details_by_name($connect, $name){
//require "../the_connector/connect_area.php";
$stmt = $connect->prepare("SELECT * FROM `projects` WHERE `project_name`=?;");
$stmt->bind_param("s", $name);
$stmt->execute();
Expand Down
63 changes: 35 additions & 28 deletions projects/get_project_details.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,41 @@

$array = ["status"=>"false", "msg"=>"No possible connection"];
if(isset($_POST["project_name"])){
$user_id = cleaner_4_DB($_POST["user_id"]);
$project_name = cleaner_4_DB($_POST["project_name"]);
// $project_description = cleaner_4_DB($_POST["project_description"]);
// $type = isset($_POST["type"]) ? cleaner_4_DB($_POST["type"]) : "private";
// $project_settings = isset($_POST["project_settings"]) ? cleaner_4_DB($_POST["project_settings"]) : "";
// $addon = isset($_POST["addon"]) ? cleaner_4_DB($_POST["addon"]) : "";
// $date = date('Y-m-d H:i:s');
// $date_updated = date('Y-m-d H:i:s');

// $project_location = $project_name . generate_faster() . '.html';

//$project_path = '../../storage/projects/' . $project_location ;
//$project_content = $_POST["project_content"];

$array = array();
$project_already = 0;

$project_already = num_count_user_project($connect, $project_name, $user_id);
//echo $user_already;
if( $project_already == 1){
//$array = ["status"=>"false", "msg"=>"This project already exist."];
$project = get_projects_details_by_name($project_name);
$array = ["status"=>"true", "project"=>$project, "msg"=>"Successfully loaded project details."];
}else if($project_already < 1 ){
$array = ["status"=>"false", "msg"=>"This project does not exist."];
}else{
$array = ["status"=>"false", "msg"=>"You may have entered invalid details."];
}
if( isset($_POST["user_id"]) ){
// $project_description = cleaner_4_DB($_POST["project_description"]);
// $type = isset($_POST["type"]) ? cleaner_4_DB($_POST["type"]) : "private";
// $project_settings = isset($_POST["project_settings"]) ? cleaner_4_DB($_POST["project_settings"]) : "";
// $addon = isset($_POST["addon"]) ? cleaner_4_DB($_POST["addon"]) : "";
// $date = date('Y-m-d H:i:s');
// $date_updated = date('Y-m-d H:i:s');

// $project_location = $project_name . generate_faster() . '.html';

//$project_path = '../../storage/projects/' . $project_location ;
//$project_content = $_POST["project_content"];
$user_id = cleaner_4_DB($_POST["user_id"]);
$project_name = cleaner_4_DB($_POST["project_name"]);

$array = array();
$project_already = 0;

//echo $project_name;

$project_already = num_count_user_project($connect, $project_name, $user_id);
//echo $user_already;
if( $project_already == 1){
//$array = ["status"=>"false", "msg"=>"This project already exist."];
$project = get_projects_details_by_name($connect, $project_name);
$array = ["status"=>"true", "project"=>$project, "msg"=>"Successfully loaded project details."];
}else if($project_already < 1 ){
$array = ["status"=>"false", "msg"=>"This project does not exist."];
}else{
$array = ["status"=>"false", "msg"=>"You may have entered invalid details."];
}
}else{
$array = ["status"=>"false", "msg"=>"Invalid User: Looks like you are not logged in."];
}

}

echo json_encode($array);
Expand Down
98 changes: 53 additions & 45 deletions projects/save_project.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

include "../the_connector/connect_area.php";
#defined( 'BASEPATH', __DIR__.'/' );
include "../the_connector/connect_area.php";
include "../users/get_users.php";
//include "hashing/all_hash_algo.php";
include "../sanitizer/clean_up.php";
Expand All @@ -9,54 +9,62 @@
include "get_project.php";

$array = ["status"=>"false", "msg"=>"No possible connection"];
if( isset($_POST["project_content"]) and isset($_POST["project_name"])){
$user_id = cleaner_4_DB($_POST["user_id"]);
//TODO::
// receive the public key from the user and verify it with the secretly stored privately key
// we may need to return the user_id after verification and stop showing it to users...
$project_name = cleaner_4_DB($_POST["project_name"]);
$project_description = cleaner_4_DB($_POST["project_description"]);
// $type = isset($_POST["type"]) ? cleaner_4_DB($_POST["type"]) : "private";
// $project_settings = isset($_POST["project_settings"]) ? cleaner_4_DB($_POST["project_settings"]) : "";
// $addon = isset($_POST["addon"]) ? cleaner_4_DB($_POST["addon"]) : "";
// $date = date('Y-m-d H:i:s');
// $date_updated = date('Y-m-d H:i:s');

session_start();
if( isset($_SESSION['userid']) ){
//$user = get_user_by_code($connect, $_SESSION['user_code']);
$user_id = $_SESSION["userid"];
if( isset($_POST["project_content"]) and isset($_POST["project_name"])){
$user_id = $user_id;
//TODO::
// receive the public key from the user and verify it with the secretly stored privately key
// we may need to return the user_id after verification and stop showing it to users...
$project_name = cleaner_4_DB($_POST["project_name"]);
$project_description = cleaner_4_DB($_POST["project_description"]);
// $type = isset($_POST["type"]) ? cleaner_4_DB($_POST["type"]) : "private";
// $project_settings = isset($_POST["project_settings"]) ? cleaner_4_DB($_POST["project_settings"]) : "";
// $addon = isset($_POST["addon"]) ? cleaner_4_DB($_POST["addon"]) : "";
// $date = date('Y-m-d H:i:s');
// $date_updated = date('Y-m-d H:i:s');



$project_content = $_POST["project_content"];

$array = array();
$project_already = 0;

$project_already = num_count_user_project($connect, $project_name, $user_id);
//echo $user_already;
if( $project_already == 1){
$project = get_projects_details_by_name($project_name);
$project_location = $project['project_location'];
$project_path = '../../storage/projects/' . $project_location;

//if(change_singles_str($connect, 'project_name', $value, $project_id )){
if($project_content != ""){
try {
//$myfile = fopen($project_path, "w") or die("Unable to open file for storage paths!");
$myfile = fopen($project_path, "w");
chmod($project_path, 0775);
fwrite($myfile, $project_content);
fclose($myfile);
if( file_exists($project_path) ){
$array = ["status"=>"true", "msg"=>"The process was successful."];

$project_content = $_POST["project_content"];

$array = array();
$project_already = 0;

$project_already = num_count_user_project($connect, $project_name, $user_id);
//echo $user_already;
if( $project_already == 1){
$project = get_projects_details_by_name($connect, $project_name);
$project_location = $project['project_location'];
$project_path = '../../storage/projects/' . $project_location;

//if(change_singles_str($connect, 'project_name', $value, $project_id )){
if($project_content != ""){
try {
//$myfile = fopen($project_path, "w") or die("Unable to open file for storage paths!");
$myfile = fopen($project_path, "w");
chmod($project_path, 0775);
fwrite($myfile, $project_content);
fclose($myfile);
if( file_exists($project_path) ){
$array = ["status"=>"true", "msg"=>"The process was successful."];
}
} catch (\Throwable $th) {
$array = ["status"=>"false", "msg"=>"Facing some issues with saving this project"];
}
} catch (\Throwable $th) {
$array = ["status"=>"false", "msg"=>"Fcing some issues with saving this project"];
}
}else if($project_already < 1 ){
$array = ["status"=>"false", "msg"=>"This has not been created"];
}else{
$array = ["status"=>"false", "msg"=>"You may have entered invalid details."];
}
}else if($project_already < 1 ){
$array = ["status"=>"false", "msg"=>"This has not been created"];
}else{
$array = ["status"=>"false", "msg"=>"You may have entered invalid details."];
}
}

}else{
$array = ["status"=>"false", "msg"=>"Invalid User: Looks like you are not logged in."];
}

echo json_encode($array);
Expand Down
1 change: 1 addition & 0 deletions sign_in.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
$_SESSION['uname'] = $user_existance["username"];
$_SESSION['userid'] = $user_existance["id"];
$_SESSION['user_code'] = $user_existance["unique_co"];
$_SESSION['public_key'] = $user_existance["public_hash"];
$_SESSION['email'] = $email;

ob_start();
Expand Down
4 changes: 3 additions & 1 deletion the_connector/connect_area.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
include "../../localhost_db_details.php";
require __DIR__."/../../localhost_db_details.php";

$connect = make_local_connect();

#You have to create file with the name above
#and then create the function above that will return a connected state to your local host
?>