0byt3m1n1
Path:
C:
/
wamp64
/
www
/
cpms_new
/
[
Home
]
File: common_model.php
<?php require_once BASE_DIR."/lib/config.php"; include_once BASE_DIR."/lib/db/connection.php"; require_once BASE_DIR."/lib/db/DBConnection.php"; class CommonModel { protected $con; public static function getProjects() { $project_details = array(); try { $user = array(); $u_id = @$_SESSION['user_id']; // Assuming you have an active database connection $con // Replace "localhost", "root", "", "cpms" with your actual database credentials $con = new mysqli("localhost", "root", "", "cpms"); if ($con->connect_error) { die("Connection failed: " . $con->connect_error); } $sql = "SELECT * FROM user WHERE user_id = ?"; $stmt = $con->prepare($sql); $stmt->bind_param("i", $u_id); $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows > 0) { $user = $result->fetch_assoc(); } else { $user = null; // No user found } if ($user["is_admin"] == 0) { // PI $sql = "SELECT * FROM addproject WHERE user_id = ?"; } else if ($user["is_admin"] == 1) { // ADMIN $sql = "SELECT * FROM addproject"; } else if ($user["is_admin"] == 2) { // ACCOUNTS $acc_type = ($user["accounts_type"] != 0) ? " AND fundtype IN (" . $user["accounts_type"] . ")" : ""; $sql = "SELECT * FROM addproject WHERE user_id = ?" . $acc_type; } else { $sql = "SELECT * FROM addproject"; } $stmt = $con->prepare($sql); if ($user["is_admin"] == 0 || $user["is_admin"] == 2) { $stmt->bind_param("i", $u_id); } $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $project_details[$row['project_id']] = $row; } } else { $project_details = null; // No projects found } $stmt->close(); $con->close(); } catch (Exception $e) { // Handle exceptions if needed echo "Error: " . $e->getMessage(); } return $project_details; } } ?>