function statusShare($statusText, $imgType, $imgData) { global $db; session_start(); $errorList = ''; $firstError = true; date_default_timezone_set("America/New_York"); $p_date = date("Y-m-d H:i:s"); if (strlen($imgData) > 0) { $data = explode(',', $imgData); $img = str_replace(' ', '+', $data[1]); $img2 = base64_decode($img); $tmp_code = createCode(10); $im = imagecreatefromstring($img2); imagejpeg($im, 'photos/tmp/' . $tmp_code . '.jpg'); imagedestroy($im); if (file_exists('photos/tmp/' . $tmp_code . '.jpg')) { $code = createCode(40); } $sql = "INSERT INTO photo (u_id, p_code, p_type, p_date, p_status) VALUES(:u_id, :p_code, '1', :p_date, '1')"; $stmt = $db->prepare($sql); $stmt->bindParam(':u_id', $_SESSION['user']->u_id, PDO::PARAM_INT); $stmt->bindParam(':p_code', $code, PDO::PARAM_STR); $stmt->bindParam(':p_date', $p_date, PDO::PARAM_STR); try { $stmt->execute(); $id = $db->lastInsertId(); } catch (Exception $e) { if ($firstError) { $errorList .= 'Photo could not insert to table!'; $firstError = false; } else { $errorList .= '<br />Photo could not insert to table!'; } } if ($firstError == false) { $result['status'] = 'error'; $result['msg'] = $errorList; echo json_encode($result); exit; } copy('photos/tmp/' . $tmp_code . '.jpg', 'photos/status/' . $id . '.jpg'); unlink('photos/tmp/' . $tmp_code . '.jpg'); $sql = "INSERT INTO user_status (u_id, p_id, us_text, us_date) VALUES (:u_id, :p_id, :us_text, :us_date)"; $stmt = $db->prepare($sql); $stmt->bindParam(':u_id', $_SESSION['user']->u_id, PDO::PARAM_INT); $stmt->bindParam(':p_id', $id, PDO::PARAM_INT); $stmt->bindParam(':us_text', $statusText, PDO::PARAM_STR); $stmt->bindParam(':us_date', $p_date, PDO::PARAM_STR); try { $stmt->execute(); $id = $db->lastInsertId(); } catch (Exception $e) { if ($firstError) { $errorList .= 'Status text could not updated with photo!'; $firstError = false; } else { $errorList .= '<br />Status text could not updated with photo!'; } } if ($firstError == false) { $result['status'] = 'error'; $result['msg'] = $errorList; echo json_encode($result); exit; } if (strlen($statusText) > 0) { $type = 'u_shared_photo_and_text'; $action = addUserAction($_SESSION['user']->u_id, $id, $type); } else { $type = 'u_shared_photo'; $action = addUserAction($_SESSION['user']->u_id, $id, $type); } } else { if (strlen($statusText) > 0) { $sql = "INSERT INTO user_status (u_id, us_text, us_date) VALUES (:u_id, :us_text, :us_date)"; $stmt = $db->prepare($sql); $stmt->bindParam(':u_id', $_SESSION['user']->u_id, PDO::PARAM_INT); $stmt->bindParam(':us_text', $statusText, PDO::PARAM_STR); $stmt->bindParam(':us_date', $p_date, PDO::PARAM_STR); try { $stmt->execute(); $id = $db->lastInsertId(); } catch (Exception $e) { if ($firstError) { $errorList .= 'Status text could not updated!'; $firstError = false; } else { $errorList .= '<br />Status text could not updated!'; } } if ($firstError == false) { $result['status'] = 'error'; $result['msg'] = $errorList; echo json_encode($result); exit; } $type = 'u_shared_text'; $action = addUserAction($_SESSION['user']->u_id, $id, $type); } } if ($firstError == false) { $result['status'] = 'error'; $result['msg'] = $errorList; echo json_encode($result); exit; } $result['status'] = 'success'; $result['msg'] = 'Status updated'; echo json_encode($result); }
function addUser() { session_start(); if (isset($_SESSION['fName']) && isset($_SESSION['lName']) && isset($_SESSION['email'])) { $projectName = $_POST["projectName"]; $createdBy = $_POST["createdBy"]; $username = $_POST['email']; $result = addUserAction($username, $projectName, $createdBy); if ($result["statusTxt"] == "SUCCESS") { echo json_encode(array("statusTxt" => "SUCCESS")); } else { header('HTTP/1.1 406, Error in DB'); die(json_encode($result)); } } else { header('HTTP/1.1 406 Session has expired, you will be redirected to the login'); die(json_encode(array('statusTxt' => 'Session has expired'))); } }