getOne() public method

A convenient SELECT * function to get one record.
public getOne ( string $tableName, string $columns = '*' ) : array
$tableName string The name of the database table to work with.
$columns string Desired columns
return array Contains the returned rows from the select query.
示例#1
0
/**
 * send message to all users
 * @param $text
 * @param $chatid
 * @param $status
 * @param MysqliDb $db
 * @param TelegramBot\Api\BotApi $bot
 */
function sendMessageToAll($text = null, $chatid, $status, $db, $bot)
{
    //this is use for hide confirm keyboard
    $hideKeys = new \TelegramBot\Api\Types\ReplyKeyboardHide(true);
    if ($status == 1) {
        //confirm keyboard
        $keys = new \TelegramBot\Api\Types\ReplyKeyboardMarkup(array(array("بله", "خیر")), false, true, true);
        if ($text == null) {
            //admin is going to send next message and next message stored
            $db->orderBy('ID', 'DESC');
            $q = $db->getOne('nextMessages', array('text'));
            $text = $q['text'];
        }
        $db->update('adminOperations', array('message' => $text));
        $status = 2;
        //admin get confirm
        $msg = "پیام زیر برای همه کاربران ارسال خواهد شد. آیا برای ارسال پیامها اطمینان دارید؟\n\n";
        $msg .= $text;
        $bot->sendMessage($chatid, $msg, true, null, $keys);
    } elseif ($status == 2 && $text == 'بله') {
        //get all user and send message for them
        $users = $db->get('users');
        $db->orderBy('ID', 'DESC');
        //custom message and next message temporary stored in adminOperations table
        $q = $db->getOne('adminOperations', array('message'));
        $message = $q['message'];
        foreach ($users as $user) {
            try {
                $bot->sendMessage($user['ID'], $message);
            } catch (Exception $e) {
                error_log($e->getMessage());
            }
        }
        $bot->sendMessage($chatid, 'پیام مورد نظر ارسال شد', true, null, $hideKeys);
        $status = 0;
    } else {
        $bot->sendMessage($chatid, 'ارسال پیام لغو شد', true, null, $hideKeys);
        $status = 0;
    }
    $db->update('adminOperations', array('send_status' => $status));
}
示例#2
0
 /**
  * Convinient function to fetch one object. Mostly will be togeather with where()
  *
  * @access public
  * @param array|string $fields Array or coma separated list of fields to fetch
  *
  * @return dbObject
  */
 private function getOne($fields = null)
 {
     $results = $this->db->getOne($this->dbTable, $fields);
     $this->processArrays($results);
     $this->processWith($results);
     if ($this->returnType == 'Array') {
         return $results;
     }
     $item = new static($results);
     $item->isNew = false;
     return $item;
 }
示例#3
0
 public function routeToCrm($host, $username, $password, $databaseName)
 {
     if (isset($_COOKIE['username'])) {
         $user = $_COOKIE['username'];
     }
     if (isset($_COOKIE['mdp'])) {
         //Récupération du mot de passe stocké
         $db = new MysqliDb($host, $username, $password, $databaseName);
         $db->where("user_name", $user);
         $users = $db->getOne("users");
         $pwd = $users['user_hash'];
         // Création du mot de passe hashé
         // $mdp = crypt(strtolower($_COOKIE['mdp']),$pwd);
         $mdp = $_COOKIE['mdp'];
     }
     // Login au CRM
     $url = "http://localhost/mysite/crm74/service/v4_1/soap.php?wsdl";
     require_once "../crm74/include/nusoap/lib/nusoap.php";
     //retrieve WSDL
     $client = new nusoap_client($url, 'wsdl');
     $proxy = $client->getProxy();
     //Affichage des erreurs
     $err = $client->getError();
     if ($err) {
         echo '<h2>Erreur du constructeur</h2><pre>' . $err . '</pre>';
         echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->getDebug(), ENT_QUOTES) . '</pre>';
         exit;
     }
     // login ----------------------------------------------------
     $login_parameters = array('user_auth' => array('user_name' => $user, 'password' => $mdp, 'version' => '1'), 'application_name' => 'SugarTest');
     $login_result = $client->call('login', $login_parameters);
     echo '<pre>';
     //get session id
     $session_id = $login_result['id'];
     $result = $proxy->seamless_login($session_id);
     // Ouverture de la session SuiteCRM
     header("Location: http://localhost/mysite/crm74/index.php?module=Administration&action=index&MSID={$session_id}");
 }
示例#4
0
echo '	<body>' . "\n";
if (isset($_POST['submitted'])) {
    $submited = $_POST['submitted'];
    $name = explode(" ", $_POST['name']);
    $pass = $_POST['pass'];
    if (isset($pass) && !empty($pass)) {
        if (isset($name) && !empty($name[0])) {
            if (count($name) >= 1 && count($name) <= 2) {
                if (count($name) > 1) {
                    $db->where('fName', $name[0]);
                    $db->where('lName', $name[1]);
                } else {
                    $db->where('fName', $name);
                    $db->orWhere('lName', $name);
                }
                $user = $db->getOne("Users");
                $hash = $user['password'];
                if (password_verify($pass, $hash)) {
                    echo 'Password is valid!';
                    $_SESSION['user'] = new User($user['id'], $user['fName'], $user['lName'], $user['admin']);
                } else {
                    echo 'Invalid password.';
                }
            } else {
                echo "invalid Name given";
            }
        } else {
            echo "You must enter a name";
        }
        //header('Location: index.php');
    } else {
示例#5
0
 if ($accion_form == ACCION_OBTERNER_POR_ID) {
     $parametros = $postdata->form_parametros;
     foreach ($parametros as $parametro_key => $parametro_valor) {
         //        var_dump($parametro_key);
         //        var_dump($parametro_valor);
         foreach ($parametro_valor as $key => $val) {
             //          var_dump($key);
             //          var_dump($val);
             switch ($key) {
                 case PARAMETRO_ID:
                     $bd->where(COLUMNA_ID, (int) $val);
                     break;
             }
         }
     }
     $query = $bd->getOne(TABLA_CATEGORIA);
     $arr = array(RESPUESTA_DATA => $query, RESPUESTA_MENSAJE => MENSAJE_OK, RESPUESTA_ERROR => ERROR_NINGUNO);
 } else {
     if ($accion_form == ACCION_AGREGAR) {
         $data_post = $postdata->form_data;
         if (!isset($data_post->FOTO)) {
             $data_post->FOTO = NULL;
         }
         $datos = array(COLUMNA_NOMBRE => $data_post->NOMBRE, COLUMNA_DESCRIPCION => $data_post->DESCRIPCION, COLUMNA_ESTADO => $data_post->ESTADO, COLUMNA_FOTO => $data_post->FOTO);
         $id_nuevo = $bd->insert(TABLA_CATEGORIA, $datos);
         if (!$id_nuevo) {
             $arr = array(RESPUESTA_ERROR => $bd->getLastError());
         } else {
             $datos[COLUMNA_ID] = $id_nuevo;
             $arr = array(RESPUESTA_DATA => $datos, RESPUESTA_MENSAJE => MENSAJE_OK, RESPUESTA_ERROR => ERROR_NINGUNO);
         }
示例#6
0
                 $bd->delete(TABLA_REL_PRODUCTO_CATEGORIA);
                 $query = $bd->get(TABLA_PRODUCTO);
                 $arr = array(RESPUESTA_DATA => $query, RESPUESTA_MENSAJE => MENSAJE_OK, RESPUESTA_ERROR => ERROR_NINGUNO);
             } else {
                 if ($accion_form == ACCION_OBTERNER_POR_ID) {
                     $parametros = $postdata->form_parametros;
                     foreach ($parametros as $parametro_key => $parametro_valor) {
                         foreach ($parametro_valor as $key => $val) {
                             switch ($key) {
                                 case PARAMETRO_ID:
                                     $bd->where(COLUMNA_ID, (int) $val);
                                     break;
                             }
                         }
                     }
                     $query = $bd->getOne(TABLA_PRODUCTO);
                     $bd->where(COLUMNA_ID_PRODUCTO, $query[COLUMNA_ID_M]);
                     $referencias = $bd->get(TABLA_REL_PRODUCTO_CATEGORIA);
                     foreach ($referencias as $parametro_key => $parametro_valor) {
                         // AGREGOS LAS CATEGORIAS A LA QUE PERTENECE CADA PRODUCTO
                         $bd->where(COLUMNA_ID, $parametro_valor[COLUMNA_ID_CATEGORIA]);
                         $referencias_aux = $bd->getOne(TABLA_CATEGORIA);
                         $referencias[$parametro_key] = $referencias_aux;
                     }
                     $query[VALOR_CATEGORIAS] = $referencias;
                     $arr = array(RESPUESTA_DATA => $query, RESPUESTA_MENSAJE => MENSAJE_OK, RESPUESTA_ERROR => ERROR_NINGUNO);
                 }
             }
         }
     }
 }
示例#7
0
 public function getTranslation($lang, $format)
 {
     if ($this->trailID == "undefined") {
         return "Trail ID has not been defined. Call setID({$ID}) before requesting data.";
     } else {
         $db = new MysqliDb(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
         $db->where("trail_id", $this->trailID);
         $db->where("lang", $lang);
         if ($db->has("translations")) {
             $db->where("trail_id", $this->trailID);
             $db->where("lang", $lang);
             $result = $db->getOne("translations");
             $attractions = json_decode(stripslashes($result['attractions']));
             $result['attractions'] = $attractions;
             $loops = json_decode(stripslashes($result['loops']));
             $result['loops'] = $loops;
             if ($format == "JSON") {
                 return json_encode($result);
             } elseif ($format == "XML") {
                 return "Maybe someday..";
             } else {
                 return $result;
             }
         } else {
             return "Elang";
         }
     }
 }
示例#8
0
    error_log("خطا در دریافت اطلاعات\n\n" . $e->getMessage());
}
$text = strtolower($text);
$bot = new TelegramBot\Api\BotApi(TOKEN);
try {
    switch ($text) {
        case '/start':
        case '/start@softwaretalkbot':
            $message = "سلام\nبه ربات جلسات باز نرم افزاری خوش آمدید.\nجهت اطلاع از جلسه آتی عبارت next را ارسال کنید.";
            $bot->sendMessage($chatid, $message);
            break;
        case '/next':
        case '/next@softwaretalkbot':
        case 'next':
            $db->orderBy('ID', 'DESC');
            $q = $db->getOne('nextMessages');
            $message = $q['text'];
            $bot->sendMessage($chatid, $message);
            break;
        case '/about':
        case '/about@softwaretalkbot':
        case 'about':
            $bot->sendMessage($chatid, "من اطلاعات جلسات باز نرم افزاری مشهد را برایتان ارسال میکنم.\n" . "سورس من روی گیت هاب قرار دارد. می توانید از طریق لینک زیر آن را مشاهده کنید:\n" . "https://github.com/mnameghi/SoftwareTalks");
            break;
            //set next message
        //set next message
        case COMMAND1:
        case '/' . COMMAND1:
            if (!isAdmin($chatid, $db)) {
                return;
            }
示例#9
0
 public function checkSession()
 {
     $db = new MysqliDb(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
     $db->where("user_id", $_SESSION['user_id']);
     $user = $db->getOne("logged_in_member");
     if ($user) {
         //Check ID and Token
         if (session_id() == $user['session_id'] && $_SESSION['token'] == $user['token']) {
             //Id and token match, refresh the session for the next request
             $this->refreshSession();
             return "auth";
         } else {
             return "unauth";
         }
     } else {
         return "unauth";
     }
 }
示例#10
0
<?php

require_once 'inc/MysqliDb.php';
require_once 'inc/HtmlDiff.php';
$db = new MysqliDb();
$db->where('id', $_GET['id']);
$history = $db->getOne('history');
$db->where('contract_id', $history['contract_id']);
$db->where('doc_id', $history['doc_id']);
$historys = $db->get('history');
if (!isset($_GET['toid']) || $_GET['toid'] == null || $_GET['toid'] == "" || $_GET['toid'] == 0) {
    $db->where('id', $history['contract_id']);
    $contracts = $db->getOne('contracts');
    $index = $history['doc_id'];
    $contract_content = json_decode($contracts['content']);
    $to_text = $contract_content[$index]->content;
} else {
    $db->where('id', $_GET['toid']);
    $to_history = $db->getOne('history');
    $to_text = $to_history['content'];
}
$from_text = $history['content'];
// $opcodes = FineDiff::getDiffOpcodes($from_text, $to_text);
// echo FineDiff::renderDiffToHTMLFromOpcodes($from_text, $opcodes);
$diff = new HtmlDiff($from_text, $to_text);
$diff->build();
?>
<html>
<head>
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
	<script type="text/javascript" src="../assets/js/jquery/jquery-1.7.1.min.js"></script>
示例#11
0
function systemStatusUpdateEmail($id, $message)
{
    $db = new MysqliDb();
    $db->where('id', $_GET['id']);
    $contract = $db->getOne('contracts');
    $to = $contract['client_email'];
    $subject = "";
    $encrypt = new Encryption();
    $link = $encrypt->encode($id);
    $message = "Updates have been made to one or more of your documents. Please click the link below to review and approve the changes.\n http://" . $_SERVER['HTTP_HOST'] . "/contract_gen/contract.php?id=" . $link;
    $headers = 'From: support@ignitorlabs.com' . "\r\n" . 'Reply-To: ' . $contract['ignitor_email'] . "\r\n" . 'X-Mailer: PHP/' . phpversion();
    mail($to, $subject, $message, $headers);
}
示例#12
0
require_once 'MysqliDb.php';
//Extracts question from forms and stores into database
$question_username = "******";
//$_POST['question_username'];
$question = "college canteen needs to be improved";
//$_POST['question'];
$description = "details";
//$_POST['description'];
$type = "general";
//$_POST['branch'];                //branch or general
$timestamp = date('Y-m-d H:i:s');
$db = new MysqliDb('localhost', 'root', 'hack123', 'colgpolls');
$data = array("question" => $question, "description" => $description, "question_username" => $question_username, "timestamp" => $timestamp);
$id = $db->insert('polls', $data);
$db->where("timestamp", $timestamp);
$user = $db->getOne("polls");
$data = array("pid" => $user['pid']);
/* There are two types of question category : general or branch based
	Store values according catogery in database */
if ($type == 'general') {
    $db->insert('CSE', $data);
    $db->insert('MECH', $data);
    $db->insert('TCE', $data);
    $db->insert('ECE', $data);
} else {
    if ($type == 'CSE') {
        $db->insert('CSE', $data);
    } else {
        if ($type == 'TCE') {
            $db->insert('TCE', $data);
        } else {
 /** Returns the given database connector for a given database connector type */
 public function getDatabaseConnectorOfType($type, $dbhost = null, $dbname = null, $dbuser = null, $dbpass = null, $dbport = null)
 {
     if (empty($dbhost) && defined('DB_HOST')) {
         $dbhost = DB_HOST;
     }
     if (empty($dbname) && defined('DB_NAME')) {
         $dbname = DB_NAME;
     }
     if (empty($dbuser) && defined('DB_USERNAME')) {
         $dbuser = DB_USERNAME;
     }
     if (empty($dbpass) && defined('DB_PASSWORD')) {
         $dbpass = DB_PASSWORD;
     }
     if (empty($dbport) && defined('DB_PORT')) {
         $dbport = DB_PORT;
     }
     if ($type == CRM_DB_CONNECTOR_TYPE_MYSQL) {
         // MySQL Database connector
         require_once "db_connectors/MysqliDb.php";
         try {
             @($mysqldb = new \MysqliDb($dbhost, $dbuser, $dbpass, $dbname, $dbport));
             if (empty($mysqldb)) {
                 throw new \Exception("Database access failed. Incorrect credentials or missing parameters.");
                 return null;
             }
             // try to set the timezone (for dates).
             $mysqldb->where("setting", CRM_SETTING_TIMEZONE);
             $mysqldb->where("context", CRM_SETTING_CONTEXT_CREAMY);
             if ($result = $mysqldb->getOne(CRM_SETTINGS_TABLE_NAME)) {
                 $timezone = $result["value"];
                 if (isset($timezone)) {
                     date_default_timezone_set($timezone);
                 }
             } else {
                 // fallback.
                 if (defined('CRM_TIMEZONE')) {
                     $timezone = CRM_TIMEZONE;
                 }
                 if (defined('CRM_LOCALE')) {
                     date_default_timezone_set($timezone);
                 }
             }
             // return MySQL database connector
             return $mysqldb;
         } catch (\Exception $e) {
             throw new \Exception("Incorrect credentials. Access denied or incorrect parameters.");
             return null;
         }
     } else {
         throw new \Exception("Database connector {$type} not supported yet!");
     }
 }
示例#14
0
文件: config.php 项目: smit-shah/om
    define('DB_NAME', '');
}
require 'constants.php';
require 'DB.php';
$db = new MysqliDb(array('host' => DB_HOST, 'username' => DB_USER, 'password' => DB_PASSWORD, 'db' => DB_NAME, 'port' => 3306, 'prefix' => '', 'charset' => 'utf8'));
if (!isset($_SESSION['user']) && strpos($_SERVER['REQUEST_URI'], 'login.php') === FALSE) {
    header('Location: ' . HTTP_PATH . 'user/login.php');
    die;
} else {
    if (strpos($_SERVER['REQUEST_URI'], 'logout.php') !== FALSE) {
        unset($_SESSION);
        header('Location: ' . HTTP_PATH . 'user/login.php');
        die;
    } else {
        if (isset($_POST['username']) && $_POST['username'] != '') {
            global $db;
            $db->where("name", $_POST['username']);
            $db->where("password", $_POST['password']);
            $user = $db->getOne('users');
            if ($user != '') {
                unset($user['password']);
                $_SESSION['user'] = $user;
                header('Location: ' . HTTP_PATH . '/user/dashboard.php');
                die;
            } else {
                $err = 'User not found!';
            }
        }
    }
}
require 'functions.php';
示例#15
0
    // Page footer
    public function Footer()
    {
        // Position at 15 mm from bottom
        $this->SetY(-15);
        // Set font
        $this->SetFont('helvetica', 'I', 8);
        // Page number
        $this->Cell(60, 10, $this->date, 0, false, 'L', 0, '', 0, false, 'T', 'M');
        $this->Cell(60, 10, 'V ' . $this->version, 0, false, 'C', 0, '', 0, false, 'T', 'M');
        $this->Cell(60, 10, 'Page ' . $this->getAliasNumPage() . '/' . $this->getAliasNbPages(), 0, false, 'R', 0, '', 0, false, 'T', 'M');
    }
}
$db = new MysqliDb();
$db->where('id', $_GET['id']);
$history = $db->getOne('history');
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->setVersion((string) $_GET['version'] . ".0");
$pdf->setDate($_GET['date']);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Ignitor Labs');
$pdf->setHeaderFont(false);
$pdf->setPrintHeader(false);
$pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
// $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);