public function get_all() { //ARRAY OBJECT HARU PASS GARNA $user_list = array(); //DATABASE CONNECTION $this->db->connect(); //SELECT ALL QUERY $sql = "SELECT user_id,user_name,first_name,last_name,contact_number,user_type,user_status,name,doe,img,address,objective FROM user INNER JOIN organization ON user_id = u_id"; //fetchquery $result = $this->db->fetchquery($sql); //STORE IN OBJECT AND SEND TO VIEW while ($row = $result->fetch_assoc()) { $user = new User(); $user->set_user_id($row['user_id']); $user->set_user_name($row['user_name']); $user->set_first_name($row['first_name']); $user->set_last_name($row['last_name']); $user->set_contact_number($row['contact_number']); $user->set_user_type($row['user_type']); $user->set_user_status($row['user_status']); $user->set_name($row['name']); $user->set_doe($row['doe']); $user->set_img($row['img']); $user->set_address($row['address']); $user->set_objective($row['objective']); array_push($user_list, $user); } $this->db->close(); return $user_list; }
function init_user_from_post_data(&$_user = NULL) { if (!$_user) { $_user = new User(); $_user->set_name($_POST['username']); } $_user->set_password($_POST['password']); $_user->set_firstname($_POST['firstname']); $_user->set_lastname($_POST['lastname']); $_user->set_mail($_POST['mail'], $_POST['publicmail'] == 'on'); $_user->set_do_notify($_POST['do_notify']); $_user->set_homepage($_POST['homepage']); $_user->set_im($_POST['im']); return $_user; }
private function _map_posted_data() { $user = new User(); $user->set_user_name($_POST['user_name']); $user->set_first_name($_POST['first_name']); $user->set_last_name($_POST['last_name']); $user->set_contact_number($_POST['contact_number']); if (isset($_POST['user_type'])) { $user->set_user_type($_POST['user_type']); } $user->set_user_status($_POST['user_status']); if (isset($_POST['password'])) { $user->set_password($_POST['password']); } if ($_POST['user_type'] == 'organization') { $user->set_name($_POST['name']); $user->set_doe($_POST['doe']); $user->set_address($_POST['address']); $user->set_objective($_POST['objective']); //store file $filename = $_FILES['img']['name']; $path = PUBLIC_PATH . "/pictures/orgPictures/"; move_uploaded_file($_FILES['img']['tmp_name'], $path . $filename); $savepath = PUBLIC_PATH2 . "/pictures/orgPictures/"; $user->set_img($savepath . $filename); } elseif ($_POST['user_type'] == 'welfare') { $user->set_welf_name($_POST['welf_name']); $user->set_welf_doe($_POST['welf_doe']); $user->set_welf_service($_POST['welf_service']); $user->set_welf_address($_POST['welf_address']); $user->set_welf_objective($_POST['welf_objective']); //store file $filename = $_FILES['img']['name']; $path = PUBLIC_PATH . "/pictures/welfPictures/"; move_uploaded_file($_FILES['img']['tmp_name'], $path . $filename); $savepath = PUBLIC_PATH2 . "/pictures/welfPictures/"; $user->set_welf_img($savepath . $filename); } return $user; }
function create_user($name, $email, $password) { if (is_null(get_user_by_name($name))) { $user = new User(); $user->set_name($name)->set_email($email)->set_password($password); $mysqli = new mysqli(get_db_host(), get_db_user(), get_db_password(), get_db_database()); $stmt = $mysqli->prepare("INSERT INTO user(name, email, password_hash) VALUES (?, ?, ?)"); $stmt->bind_param("sss", $user->get_name(), $user->get_email(), $user->get_password_hash()); $stmt->execute(); $stmt->close(); } }
/** * Returns the number of all users whose name is similar to the * given one. * $_name: The name for which to find similar users. */ function count_similar_users_from_name($_name) { if (!$_name) { die('UserDB::count_similar_users_from_name(): Invalid name.'); } $user = new User(); $user->set_name($_name); $soundex = $user->get_soundexed_name(); $query = new FreechSqlQuery(); $sql = "SELECT COUNT(*) FROM {t_user}"; $sql .= " WHERE soundexname={soundexname}"; $query->set_sql($sql); $query->set_string('soundexname', $soundex); $n_users = $this->db->GetOne($query->sql()); if (!$n_users) { return 0; } return $n_users; }
<?php // This script allows for checking for similar user names. May be used // when testing new algorithms for the similarity check. require_once 'adodb/adodb.inc.php'; include_once 'libuseful/SqlQuery.class.php5'; include_once 'services/sql_query.class.php'; include_once 'services/userdb.class.php'; include_once 'functions/config.inc.php'; include_once 'objects/user.class.php'; $db =& ADONewConnection(cfg("db_dbn")) or die("FreechForum::FreechForum(): Error: Can't connect." . " Please check username, password and hostname."); function print_user($user, $needle) { echo "Match: " . $user->get_name() . " = " . $user->get_lexical_similarity($needle) . "<br>"; } $userdb = new UserDB($db); $needle = new User(); $needle->set_name($_GET['name']); if ($_GET['name2']) { $user = new User(); $user->set_name($_GET['name2']); die("Similarity: " . $user->get_lexical_similarity($needle) . "<br>"); } $users = $userdb->get_similar_users_from_name($needle->get_name()); foreach ($users as $user) { print_user($user, $needle); } echo "DONE.";
/** * Helper function to create a user after applying checks on the * in parameters. Rather than throwing an exception, this returns * NULL if parameters are invalid. */ public static function create($name, $password, $email) { $email = filter_var($email, FILTER_SANITIZE_EMAIL); if (!ctype_alnum($name) || $email != NULL && !filter_var($email, FILTER_VALIDATE_EMAIL)) { return NULL; } $salt = base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)); $hash = hash('whirlpool', $salt . $password); $user = new User(); $user->set_name($name); $user->set_email($email); $user->set_salt($salt); $user->set_password_hash($hash); return $user; }
/** * Get a user object from a SQL row result. */ public static function get_user_from_row($row) { if (!$row) { return NULL; } $user = new User(); $user->set_id($row['user_id']); $user->set_name($row['user_name']); $user->set_email($row['user_email']); $user->set_salt($row['user_salt']); $user->set_password_hash($row['user_passwordhash']); return $user; }