Example #1
0
<?php

include "../includes/layouts/header.php";
require_once "../includes/functions/functions.php";
require_once "../includes/functions/db_connection.php";
if (isset($_POST["username"])) {
    if (check_available($_POST["username"]) && validateCred($_POST["username"], $_POST["password"])) {
        //echo "Username available";
        if (createUser($_POST["username"], $_POST["password"], $_POST["name"], $_POST["phone_no"], $_POST["email_id"])) {
            redirect("index.php?signedup=1");
            //echo "Account created successfully. Go to <a href=index.php>Log in</a> page.";
        }
    } else {
        echo "<p class=\"invalid_cred\">Username not available</p>";
    }
}
?>
<html>
<body>
	<h3> Enter details for signing up:</h3>
	<form name="signup" action="signup.php" method="POST" onsubmit="return validateForm()">
		<input type="text" placeholder="new username" id="username" name="username"
		value="<?php 
echo isset($_POST['username']) ? $_POST['username'] : '';
?>
" required
       oninvalid="this.setCustomValidity('User ID is a must')" oninput="setCustomValidity('')"></input>
			 <!--<input type="button" value="Check Availability" onsubmit="signup.php"></input>-->
			 <br>
		<input type="password" placeholder="password" id="password" name="password" required
       oninvalid="this.setCustomValidity('Please provide a password')" oninput="setCustomValidity('')"></input>
function read_json($path, $user_id, $filetype, $wrong_folder)
{
    $response = new Response();
    if ($filetype == "gz") {
        $path = str_replace(".tar.gz", "", $path);
    }
    if ($filetype == "zip") {
        $path = str_replace(".zip", "", $path);
    }
    // Heck correct package path
    if (is_dir($path . '/' . $wrong_folder)) {
        $response->status = 500;
        $response->message = 'Package file has an invalid path. Need to repack file again';
        $response->json($response);
    }
    //var_dump($path);
    $targetdir = $path . "/module.json";
    if (!file_exists($targetdir)) {
        $response->status = 500;
        $response->message = 'Unable to read module.json file';
        $response->json($response);
    }
    $jsonfile = @file_get_contents("{$targetdir}");
    $jsonarray = json_decode($jsonfile, true);
    $category = $jsonarray['category'];
    $author = $jsonarray['author'];
    $homepage = $jsonarray['homepage'];
    $version = $jsonarray['version'];
    $maturity = $jsonarray['maturity'];
    $moduleName = $jsonarray['moduleName'];
    $dependencies = $jsonarray['dependencies'];
    $modulejson = $jsonfile;
    $latest = date('Ymdhis');
    $lang_target = $path . "/lang";
    if (file_exists($lang_target . "/de.json")) {
        //echo "DE: OK";
        $jsonfile_lang = file_get_contents($lang_target . "/de.json");
        $jsonarray_lang = json_decode($jsonfile_lang, true);
        $de_desc = $jsonarray_lang['m_descr'];
        $de_title = $jsonarray_lang['m_title'];
    } else {
        //echo "DE: empty";
    }
    if (file_exists($lang_target . "/en.json")) {
        //echo "en: OK";
        $jsonfile_lang = file_get_contents($lang_target . "/en.json");
        $jsonarray_lang = json_decode($jsonfile_lang, true);
        if (!$jsonarray_lang['m_descr'] || !$jsonarray_lang['m_title']) {
            $response->status = 500;
            $response->message = 'Missing m_title or m_descr in lang/en.json';
            $response->json($response);
        }
        $en_desc = $jsonarray_lang['m_descr'];
        $en_title = $jsonarray_lang['m_title'];
    } else {
        $response->status = 500;
        $response->message = 'Missing file: lang/en.json';
        $response->json($response);
    }
    if (file_exists($lang_target . "/ru.json")) {
        //echo "ru: OK";
        $jsonfile_lang = file_get_contents($lang_target . "/ru.json");
        $jsonarray_lang = json_decode($jsonfile_lang, true);
        $ru_desc = $jsonarray_lang['m_descr'];
        $ru_title = $jsonarray_lang['m_title'];
    } else {
        //echo "ru: empty";
    }
    if ($en_title == "" || $en_desc == '') {
        $response->status = 500;
        $response->message = 'Empty m_title or m_descr in lang/en.json';
        $response->json($response);
    }
    //    if ($en_title == "") {
    //        $jsonfile = file_get_contents("$targetdir");
    //        $jsonarray = json_decode($jsonfile, true);
    //        $en_title = $jsonarray['defaults']['title'];
    //    }
    $copy = check_available($user_id, $en_title, $path, $moduleName, $filetype);
    if ($copy == "ok") {
        $jsonfile = file_get_contents("{$targetdir}");
        $jsonarray = json_decode($jsonfile, true);
        $response = store_json($jsonarray, $targetdir, $path, $user_id, $filetype, $jsonfile);
    } else {
        return "error";
    }
}