This repository was archived by the owner on Apr 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpgconnect.php
More file actions
82 lines (81 loc) · 2.41 KB
/
pgconnect.php
File metadata and controls
82 lines (81 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/**
* AMS Archive Management System
*
*
* PHP version 5
*
* @category AMS
* @package PHP
* @subpackage pgconnect
* @author Nouman Tayyab <nouman@avpreserve.com>
* @copyright Copyright (c) WGBH (http://www.wgbh.org/). All Rights Reserved.
* @license http://www.gnu.org/licenses/gpl.txt GPLv3
* @version GIT: <$Id>
* @link https://github.com/avpreserve/AMS
*/
$dbconnection = pg_connect("host=localhost port=5432 dbname=mint user=mint password=mint");
if ($dbconnection)
{
if (isset($_REQUEST['mint_id']))
{
if ($_REQUEST['mint_id'] == '')
{
$p_query = pg_query($dbconnection, "SELECT nextval('seq_users_id')");
$user_id = pg_fetch_row($p_query);
$username = explode('@', $_REQUEST['username']);
$random = rand(1, 99);
$final_username = $username[0] . '_' . $random;
$data = array(
'login' => $final_username,
'first_name' => $_REQUEST['first_name'],
'last_name' => $_REQUEST['last_name'],
'email' => $_REQUEST['username'],
'md5_password' => md5($final_username . 'x0h0@123'),
'organization_id' => 1,
'account_created' => date('Y-m-d'),
'active_account' => 't',
'rights' => $_REQUEST['rights'],
'users_id' => $user_id[0]
);
$result = pg_insert($dbconnection, 'users', $data);
if ($result)
{
$email = $_REQUEST['username'];
$p_query = pg_query($dbconnection, "SELECT * FROM users WHERE email = '$email'");
if ($p_query)
{
$user_info = pg_fetch_row($p_query);
$response = json_encode(array("success" => 'true', 'error' => '', 'result' => $user_info, 'user_id' => $_REQUEST['user_id']));
echo $_GET['callback'] . '(' . $response . ')';
exit;
}
}
else
{
$response = json_encode(array("success" => 'false', 'error' => 'something went wrong while inserting.'));
echo $_GET['callback'] . '(' . $response . ')';
exit;
}
}
else
{
$user_id = $_REQUEST['mint_id'];
$result = pg_query($dbconnection, "SELECT * FROM users WHERE users_id = $user_id");
if ($result)
{
$user_info = pg_fetch_row($result);
$response = json_encode(array("success" => 'true', 'error' => '', 'result' => $user_info, 'user_id' => $_REQUEST['user_id']));
echo $_GET['callback'] . '(' . $response . ')';
exit;
}
}
}
}
else
{
$response = json_encode(array("success" => 'false', 'error' => 'Connection with pg failed.'));
echo $_GET['callback'] . '(' . $response . ')';
exit;
}
?>