Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * Auther @ Mads Roloff - Rights reservede to Author
- * Date: 17-05-2017
- */
- class user
- {
- private $db;
- public $iUserID = -1;
- public $vcImage;
- public $vcUserName;
- public $vcPassword;
- public $vcFirstName;
- public $vcLastName;
- public $iOrgID;
- public $vcAddress;
- public $iZip;
- public $vcCity;
- public $vcEmail;
- public $vcPhone1;
- public $vcPhone2;
- public $vcPhone3;
- public $daCreated;
- public $iSuspended;
- public $iDeleted;
- public $arrFormElms = array();
- public $arrLabels = array();
- public $arrColumns = array();
- public $arrValues = array();
- public $unset = array();
- public function __construct()
- {
- global $db;
- $this->db = $db;
- $this->CreateTable();
- $this->Table = "user";
- $this->arrFormElm = array(
- "iUserID" => array("label" => "", "type" => "hidden", "placeholder" => "", "required" => "data-requried='1'", "dbname" => "iUserID", "Filter" => FILTER_SANITIZE_NUMBER_INT),
- "vcFirstName" => array("label" => "First Name", "type" => "text", "placeholder" => "First name", "required" => "data-requried='1'", "dbname" => "vcFirstName", "Filter" => FILTER_SANITIZE_STRING),
- "vcLastName" => array("label" => "Last Name", "type" => "text", "placeholder" => "Last name", "required" => "data-requried='1'", "dbname" => "vcLastName", "Filter" => FILTER_SANITIZE_STRING),
- "vcUserName" => array("label" => "user name", "type" => "text", "placeholder" => "Username", "required" => "data-requried='1'", "dbname" => "vcUserName", "Filter" => FILTER_SANITIZE_STRING),
- "vcPassword" => array("label" => "password", "type" => "password", "placeholder" => "Password", "required" => "data-requried='1'", "dbname" => "vcPassword", "Filter" => FILTER_SANITIZE_STRING),
- "vcAddress" => array("label" => "Adresse", "type" => "text", "placeholder" => "Address", "required" => "data-requried='1'", "dbname" => "vcAddress", "Filter" => FILTER_SANITIZE_STRING),
- "iZip" => array("label" => "Zip code", "type" => "text", "placeholder" => "Zip Code", "required" => "data-requried='1'", "dbname" => "iZip", "Filter" => FILTER_SANITIZE_NUMBER_INT),
- "vcCity" => array("label" => "City", "type" => "text", "placeholder" => "City", "required" => "data-requried='1'", "dbname" => "vcCity", "Filter" => FILTER_SANITIZE_STRING),
- "vcEmail" => array("label" => "Email", "type" => "email", "placeholder" => "Email", "required" => "data-requried='1'", "dbname" => "vcEmail", "Filter" => FILTER_SANITIZE_STRING),
- "vcPhone1" => array("label" => "Phone Number", "type" => "tel", "placeholder" => "Phone Number", "required" => "data-requried='1'", "dbname" => "vcPhone1", "Filter" => FILTER_SANITIZE_NUMBER_INT),
- "vcPhone2" => array("label" => "Phone Number", "type" => "tel", "placeholder" => "Phone Number", "required" => "data-requried='1'", "dbname" => "vcPhone2", "Filter" => FILTER_SANITIZE_NUMBER_INT),
- "daCreated" => array("label" => "", "type" => "hidden", "placeholder" => "", "required" => "data-requried='1'", "dbname" => "daCreated", "Filter" => FILTER_SANITIZE_NUMBER_INT),
- //Unneeded fields
- //"iSuspended" => array(),
- //"iDeleted" => array(),
- //"iOrgID" => array("label" => "", "type" => "hidden", "placeholder" => "",),
- //"vcImage" => array("label" => "Image", "shpwn", "type" => "text", "require" => "", "placeholder" => "Pick a image",),
- );
- }
- public function GetSelect()
- {
- $sql = "select * from $this->Table WHERE iDeleted = 0";
- return $this->db->_fetch_array($sql, array());
- }
- public function GetList()
- {
- $sql = "SELECT * FROM $this->Table WHERE iDeleted = 0";
- //Shows Column names from "user"
- $sqlLabels = "SHOW FULL COLUMNS FROM $this->Table";
- $this->arrLabels = $this->db->_fetch_array($sqlLabels, array());
- $this->arrValues = $this->db->_fetch_array($sql, array());
- //UNSET = Columns to avoid in LIST
- $this->unset = array(
- "iUserID",
- "vcPassword",
- "vcPassword2",
- "iUserRole",
- "vcPhone2",
- "vcPhone3",
- "iOrgID",
- "daCreated",
- "iSuspended",
- "iDeleted",
- "vcCity",
- "iZip"
- );
- }
- public function getDetails($iUserID)
- {
- $sql = "SELECT * FROM $this->Table WHERE iDeleted = 0 AND IUserID = ?";
- //Shows Column names from "user"
- $sqlLabels = "SHOW FULL COLUMNS FROM $this->Table";
- $this->arrLabels = $this->db->_fetch_array($sqlLabels, array());
- $this->arrValues = $this->db->_fetch_array($sql, array($iUserID));
- //UNSET = Columns to avoid in LIST
- $this->unset = array(
- "iUserID",
- "vcPassword",
- "vcPassword2",
- "iUserRole",
- "vcPhone2",
- "vcPhone3",
- "iOrgID",
- "daCreated",
- "iSuspended",
- "iDeleted",
- "vcCity",
- "iZip"
- );
- }
- public function getUser($iUserID)
- {
- $this->iUserID = $iUserID;
- $sql = "SELECT * FROM $this->Table WHERE iDeleted = 0 AND iUserID = ?";
- $row = $this->db->_fetch_array($sql, array($this->iUserID));
- foreach ($row[0] as $key => $value) {
- $this->$key = $value;
- }
- }
- public function UpdateUser($iUserID)
- {
- //unsets IUserID from the array
- unset($this->arrFormElm["iUserID"]);
- //MAkes a foreach that gets "filter" from $arrFormElm
- foreach ($this->arrFormElm as $key => $value) {
- $f[$key] = filter_input(INPUT_POST, $key, $value["Filter"]);
- }
- //uses the value of the "filter"'s and takes the value from the $_POST and inserts them into an array ordered by the "FIlTER"
- $params = array_values($f);
- //iUserID = IUserID
- $this->iUserID = $iUserID;
- //awesome SQL that makes an string that looks like this
- //"UPDATE user SET vcFirstName = ?, vcLastName = ?, vcUserName = ?, vcPassword = ?, vcAddress = ?, iZip = ?, vcCity = ?, vcEmail = ?, vcPhone1 = ?, vcPhone2 = ? WHERE iUserID = 12"
- echo $sql = "UPDATE $this->Table SET " . implode(array_keys($this->arrFormElm), " = ?, ") . " = ? WHERE iUserID = $this->iUserID";
- return $this->db->_query($sql, $params);
- }
- public function DeleteUser($iUserID)
- {
- $this->iUserID = $iUserID;
- //SQL that sets iDeleted to 1
- $sql = "UPDATE $this->Table SET iDeleted = 1 WHERE iUserID = ?";
- return $this->db->_query($sql, array($iUserID));
- }
- public function SaveUser()
- {
- }
- Public function CreateUser($iUserID)
- {
- //unsets IUserID from the array
- unset($this->arrFormElm["iUserID"]);
- unset($this->arrFormElm["daCreated"]);
- //Makes a foreach that gets "filter" from $arrFormElm
- foreach ($this->arrFormElm as $key => $value) {
- $f[$key] = filter_input(INPUT_POST, $key, $value["Filter"]);
- }
- //uses the value of the "filter"'s and takes the value from the $_POST and inserts them into an array ordered by the "FIlTER"
- $params = array_values($f);
- //iUserID = IUserID
- $this->iUserID = $iUserID;
- //awesome SQL that makes an string that looks like this
- //"UPDATE user SET vcFirstName = ?, vcLastName = ?, vcUserName = ?, vcPassword = ?, vcAddress = ?, iZip = ?, vcCity = ?, vcEmail = ?, vcPhone1 = ?, vcPhone2 = ? WHERE iUserID = 12"
- $sql = "INSERT INTO $this->Table SET " . implode(array_keys($this->arrFormElm), " = ?, ") . " = ?, daCreated = " . time();
- return $this->db->_query($sql, $params);
- }
- public function CreateTable()
- {
- $sql = "CREATE TABLE IF NOT EXISTS `user` (
- `iUserID` BIGINT(20) NOT NULL AUTO_INCREMENT,
- `vcUserName` VARCHAR(255) NOT NULL COMMENT 'Brugernavn' COLLATE 'utf8_unicode_ci',
- `vcPassword` VARCHAR(50) NOT NULL COMMENT 'Kodeord' COLLATE 'utf8_unicode_ci',
- `vcFirstName` VARCHAR(255) NOT NULL COMMENT 'Navn' COLLATE 'utf8_unicode_ci',
- `vcLastName` VARCHAR(255) NOT NULL COMMENT 'Efternavn' COLLATE 'utf8_unicode_ci',
- `vcAddress` VARCHAR(255) NOT NULL COMMENT 'Adresse' COLLATE 'utf8_unicode_ci',
- `iZip` MEDIUMINT(10) NOT NULL COMMENT 'Postnummer',
- `vcCity` VARCHAR(255) NOT NULL COMMENT 'By' COLLATE 'utf8_unicode_ci',
- `vcEmail` VARCHAR(255) NOT NULL COMMENT 'Email' COLLATE 'utf8_unicode_ci',
- `vcPhone1` VARCHAR(255) NOT NULL COMMENT 'Telefon 1' COLLATE 'utf8_unicode_ci',
- `vcPhone2` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Telefon 2' COLLATE 'utf8_unicode_ci',
- `vcPhone3` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Telefon 3' COLLATE 'utf8_unicode_ci',
- `iOrgID` BIGINT(20) NOT NULL DEFAULT '1' COMMENT 'Organisation',
- `daCreated` BIGINT(20) NOT NULL COMMENT 'Oprettet',
- `iSuspended` TINYINT(4) NOT NULL DEFAULT '0' COMMENT 'Suspenderet',
- `iDeleted` TINYINT(4) NOT NULL DEFAULT '0',
- PRIMARY KEY(`iUserID`))
- COLLATE = 'utf8_unicode_ci' ENGINE = MyISAM AUTO_INCREMENT = 12";
- $this->db->_query($sql);
- $sql = " CREATE TABLE IF NOT EXISTS `usersession` (
- `vcSessionID` VARCHAR(32) NOT NULL DEFAULT '',
- `iUserID` BIGINT(20) NOT NULL DEFAULT '0',
- `iIpAddress` VARCHAR(24) NOT NULL DEFAULT '',
- `iIsLoggedIn` TINYINT(1) NOT NULL DEFAULT '0',
- `daLoginCreated` BIGINT(20) NOT NULL DEFAULT '0',
- `daLastAction` BIGINT(20) NOT NULL DEFAULT '0')
- COLLATE = 'utf8_general_ci'ENGINE = MyISAM";
- $this->db->_query($sql);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement