forked from shouc/sexpert
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
268 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,41 @@ | ||
<?php | ||
|
||
require_once __DIR__ . "/../const.php"; | ||
require_once __DIR__ . "/../utils/mail.php"; | ||
|
||
function add_inquiry(WP_REST_Request $request){ | ||
global $wpdb, $INQUIRY_TABLE_NAME; | ||
$email = $request->get_param("email"); | ||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)){ | ||
wp_send_json( | ||
array( | ||
"success" => true, | ||
"message" => "Email is not valid", | ||
) | ||
); | ||
} | ||
$age = (int) $request->get_param("age"); | ||
$gender = (int) $request->get_param("gender"); | ||
$country = $request->get_param("country"); | ||
$message = $request->get_param("message"); | ||
|
||
$wpdb->insert( | ||
$INQUIRY_TABLE_NAME, | ||
array( | ||
'email' => $email, | ||
'age' => $age, | ||
'gender' => $gender, | ||
'country' => $country, | ||
'message' => $message, | ||
) | ||
); | ||
|
||
// Send an email | ||
|
||
wp_send_json( | ||
array( | ||
"success" => true, | ||
"message" => "", | ||
) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,36 @@ | ||
<?php | ||
|
||
require_once __DIR__ . "/../const.php"; | ||
require_once __DIR__ . "/../utils/user-level.php"; | ||
|
||
function assign(WP_REST_Request $request){ | ||
global $wpdb, $INQUIRY_TABLE_NAME; | ||
|
||
$id = (int) $request->get_param("id"); | ||
$assignee_id = (int) $request->get_param('assignee_id'); | ||
$assigner_id = wp_get_current_user()->ID; | ||
if ($assignee_id != $assigner_id && !authorize("admin")){ | ||
wp_send_json( | ||
array( | ||
"success" => false, | ||
"message" => "Not authorized", | ||
) | ||
); | ||
} | ||
$wpdb->update( | ||
$INQUIRY_TABLE_NAME, | ||
array( | ||
'assigner_id'=>$assigner_id, | ||
'assignee_id'=>$assignee_id, | ||
'status'=>1 | ||
), | ||
array('id'=>$id) | ||
); | ||
|
||
wp_send_json( | ||
array( | ||
"success" => true, | ||
"message" => "", | ||
) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,24 @@ | ||
<?php | ||
|
||
function comment(WP_REST_Request $request){ | ||
global $wpdb, $INQUIRY_TABLE_NAME; | ||
$id = $request->get_param("id"); | ||
$comment = $request->get_param("comment"); | ||
|
||
$wpdb->update( | ||
$INQUIRY_TABLE_NAME, | ||
array( | ||
'comment' => $comment, | ||
), | ||
array('id' => $id) | ||
); | ||
|
||
// Send an email | ||
|
||
wp_send_json( | ||
array( | ||
"success" => true, | ||
"message" => "", | ||
) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,25 @@ | ||
<?php | ||
|
||
function delete_inquiry(WP_REST_Request $request){ | ||
global $wpdb, $INQUIRY_TABLE_NAME; | ||
if (!authorize("admin")){ | ||
wp_send_json( | ||
array( | ||
"success" => false, | ||
"message" => "Not authorized", | ||
) | ||
); | ||
} | ||
$id = $request->get_param("id"); | ||
$wpdb->delete( | ||
$INQUIRY_TABLE_NAME, | ||
array('id'=>$id) | ||
); | ||
|
||
wp_send_json( | ||
array( | ||
"success" => true, | ||
"message" => "", | ||
) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,32 @@ | ||
<?php | ||
|
||
function get_inquiry(WP_REST_Request $request){ | ||
global $wpdb, $INQUIRY_TABLE_NAME; | ||
if (!authorize("admin")){ | ||
wp_send_json( | ||
array( | ||
"success" => false, | ||
"message" => "Not authorized", | ||
) | ||
); | ||
} | ||
$id = $request->get_param("id"); | ||
$assignee_id = $request->get_param('assignee_id'); | ||
$assigner_id = wp_get_current_user()->ID; | ||
$wpdb->update( | ||
$INQUIRY_TABLE_NAME, | ||
array( | ||
'assigner_id'=>$assigner_id, | ||
'assignee_id'=>$assignee_id, | ||
'status'=>1 | ||
), | ||
array('id'=>$id) | ||
); | ||
|
||
wp_send_json( | ||
array( | ||
"success" => true, | ||
"message" => "", | ||
) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,32 @@ | ||
<?php | ||
|
||
function unassign(WP_REST_Request $request){ | ||
global $wpdb, $INQUIRY_TABLE_NAME; | ||
if (!authorize("admin")){ | ||
wp_send_json( | ||
array( | ||
"success" => false, | ||
"message" => "Not authorized", | ||
) | ||
); | ||
} | ||
$id = $request->get_param("id"); | ||
$assignee_id = $request->get_param('assignee_id'); | ||
$assigner_id = wp_get_current_user()->ID; | ||
$wpdb->update( | ||
$INQUIRY_TABLE_NAME, | ||
array( | ||
'assigner_id'=>$assigner_id, | ||
'assignee_id'=>$assignee_id, | ||
'status'=>1 | ||
), | ||
array('id'=>$id) | ||
); | ||
|
||
wp_send_json( | ||
array( | ||
"success" => true, | ||
"message" => "", | ||
) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
global $wpdb; | ||
$USER_TABLE_NAME = $wpdb->prefix . "users"; | ||
$INQUIRY_TABLE_NAME = $wpdb->prefix . "sexpert_inquiries"; | ||
$COMMENT_TABLE_NAME = $wpdb->prefix . "sexpert_comments"; | ||
$GENDER_TABLE_NAME = $wpdb->prefix . "sexpert_genders"; | ||
$LIST_LIMIT = 5; | ||
|
||
function CONVERT_STATUS($status){ | ||
switch ($status): | ||
case 0: | ||
return "Unassigned"; | ||
case 1: | ||
return "Assigned"; | ||
case 2: | ||
return "Replied"; | ||
case 3: | ||
return ""; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters