Example #1
0
 /**
  * Save model data.
  * If model is new PK is null - we generate INSERT SQL request.
  * If model data already exists in DB, PK > 0 - we generate UPDATE request.
  * Method return true if model data saved successfully. False if error.
  */
 public function save($validate = true)
 {
     if ($validate === true && $this->validate() === false) {
         return false;
     }
     $columns = $this->getClearColumns();
     $values = array();
     foreach ($columns as $column) {
         $values[] = $this->{$column};
     }
     $keyPosition = array_search($this->pkColumnName(), $columns);
     array_splice($columns, $keyPosition, 1);
     array_splice($values, $keyPosition, 1);
     if ((int) $this->{$this->pkColumnName()} > 0) {
         $query = new Query("update");
         $query->addTable($this->tableName());
         foreach ($columns as $key => $column) {
             $query->addField($column, $values[$key]);
         }
         $query->where->add($this->pkColumnName() . " = " . $this->{$this->pkColumnName()});
         $result = $query->exec();
     } else {
         $query = new Query("insert");
         $query->addTable($this->tableName());
         foreach ($columns as $key => $column) {
             $query->addField($column, $values[$key]);
         }
         $result = $query->exec();
         $this->ADDRESSID = $query->last_insert_id();
     }
     return $result;
 }
Example #2
0
File: db.php Project: sd-studio/sh
function execQuery($sql, $params = array(), &$processedCount = 0)
{
    global $db;
    if (empty($params)) {
        $q = new Query($db);
        $q->exec($sql);
        return $q->processedCount();
    }
    $q = createQuery($sql, $params);
    $q->execute();
    $processedCount = $q->processedCount();
    return $db->lastInsertId();
}
Example #3
0
function get_active_theme()
{
    $theme_name = "";
    // Get a name of the active theme.
    $sql = "SELECT t.theme_name FROM theme t JOIN settings s WHERE t.themeid = s.themeid";
    $q = new Query();
    $q->connect();
    $rows = $q->exec($sql);
    if (count($rows) > 0) {
        $theme_name = $rows[0]["theme_name"];
    }
    $q->close();
    // Check theme directory existence.
    $theme = "../themes/" . $theme_name;
    if (file_exists($theme . "/style.css")) {
        return $theme_name;
    } else {
        return "";
    }
}
Example #4
0
 public static function getList($parameters = array())
 {
     $query = new Query(static::getEntity());
     if (isset($parameters['select'])) {
         $query->setSelect($parameters['select']);
     } else {
         $query->setSelect(array('*'));
     }
     if (isset($parameters['filter'])) {
         $query->setFilter($parameters['filter']);
     }
     if (isset($parameters['group'])) {
         $query->setGroup($parameters['group']);
     }
     if (isset($parameters['order'])) {
         $query->setOrder($parameters['order']);
     }
     if (isset($parameters['limit'])) {
         $query->setLimit($parameters['limit']);
     }
     if (isset($parameters['offset'])) {
         $query->setOffset($parameters['offset']);
     }
     if (isset($parameters['count_total'])) {
         $query->countTotal($parameters['count_total']);
     }
     if (isset($parameters['options'])) {
         $query->setOptions($parameters['options']);
     }
     if (isset($parameters['runtime'])) {
         foreach ($parameters['runtime'] as $name => $fieldInfo) {
             $query->registerRuntimeField($name, $fieldInfo);
         }
     }
     if (isset($parameters['data_doubling'])) {
         $parameters['data_doubling'] ? $query->enableDataDoubling() : $query->disableDataDoubling();
     }
     return $query->exec();
     // return array?
 }
Example #5
0
/**
 * Obtiene los usuarios y los <li> del
 * submenu de la derecha.
 *
 * @return array
 */
function get_users()
{
    global $db;
    global $id_users;
    $q = new Query($db);
    $q->exec('SELECT users.id_users
                   , users.username
                   , users.name
                   , users.description
              FROM users');
    $data = array();
    $submenu = '';
    for ($i = 0; $i < $q->numrows; $i++) {
        $data[$q->data['id_users']] = $q->data;
        $selected = $id_users == $q->data['id_users'] ? ' class="selected"' : '';
        $submenu .= '
<li><a href="?id_users=' . $q->data['id_users'] . '"' . $selected . '>' . $q->data['name'] . '</a></li>';
        $q->nxt();
    }
    $q->free();
    return array($data, $submenu);
}
require_once "../functions/inputFuncs.php";
require_once '../classes/DmQuery.php';
$dmQ = new DmQuery();
$dmQ->connect();
$mbrClassifyDm = $dmQ->getAssoc('mbr_classify_dm');
$mbrStatusDm = array("y" => $loc->getText("mbrActive"), "n" => $loc->getText("mbrInactive"));
$customFields = $dmQ->getAssoc('member_fields_dm');
$dmQ->close();
// Get & show the latest BarcodeNumber.
require_once "../shared/common.php";
require_once "../classes/Query.php";
$barcode = "0";
$sql = "SELECT MAX(barcode_nmbr) AS bn FROM member";
$q = new Query();
$q->connect();
$rows = $q->exec($sql);
if (count($rows) > 0) {
    $barcode = $rows[0]["bn"];
}
$q->close();
$barcode_help = $loc->getText("mbrLatestBarcode") . ": " . $barcode . " <br />";
$barcode_help .= '<input type="checkbox" id="chk_auto_barcode" name="chk_auto_barcode" value="1" /> ' . $loc->getText("mbrAutoBarcode");
$fields = array("mbrFldsClassify" => inputField('select', "classification", $mbr->getClassification(), NULL, $mbrClassifyDm), "mbrFldsStatus" => inputField('select', "status", $mbr->getStatus(), NULL, $mbrStatusDm), "mbrFldsCardNmbr" => inputField('text', "barcodeNmbr", $mbr->getBarcodeNmbr(), NULL, NULL, $barcode_help), "mbrFldsLastName" => inputField('text', "lastName", $mbr->getLastName()), "mbrFldsFirstName" => inputField('text', "firstName", $mbr->getFirstName()), "mbrFldsHomePhone" => inputField('text', "homePhone", $mbr->getHomePhone()), "mbrFldsWorkPhone" => inputField('text', "workPhone", $mbr->getWorkPhone()), "mbrFldsCel" => inputField('text', "cel", $mbr->getCel()), "mbrFldsEmail" => inputField('text', "email", $mbr->getEmail()), "mbrFldsFoto" => inputField('text', "foto", $mbr->getFoto()), "MailingAddress:" => inputField('textarea', "address", $mbr->getAddress()), "mbrFldsPassUser" => inputField('text', "passUser", $mbr->getPassUser()), "mbrFldsBornDt" => inputField('text', "bornDt", $mbr->getBornDt()), "mbrFldsOther" => inputField('textarea', "other", $mbr->getOther()));
foreach ($customFields as $name => $title) {
    $fields[$title . ':'] = inputField('text', 'custom_' . $name, $mbr->getCustom($name));
}
?>

<table class="primary">
  <tr>
    <th colspan="2" valign="top" nowrap="yes" align="left">
 function getCustomFields($mbrid)
 {
     # KLUDGE to make sure we don't clobber the results handle
     # when we're called from fetchmember().
     # FIXME - redo query stuff to avoid this issue
     $q = new Query();
     $q->connect();
     $sql = $q->mkSQL('select * from member_fields where mbrid=%N', $mbrid);
     $rows = $q->exec($sql);
     $fields = array();
     foreach ($rows as $r) {
         $fields[$r['code']] = $r['data'];
     }
     return $fields;
 }
Example #8
0
 /**
  * Verifica a existência de um campo
  *
  * @param string $tableName Nome da tabela a ser verificada
  * @param string $fieldName Nome do campo a ser verificado
  *
  * @return boolean Existe o campo?
  */
 private function fieldExists($tableName, $fieldName)
 {
     // Os nomes passados estão no padrão?
     if (!$this->validateName($tableName) || !$this->validateName($fieldName)) {
         return false;
     }
     // Pesquisa o campo na tabela
     $consulta = Query::exec("SHOW COLUMNS FROM {$tableName} WHERE Field = '{$fieldName}'");
     // O campo foi encontrado?
     return isset($consulta[0]['Field']);
 }
Example #9
0
 /**
  * Deletes the note entry from the database
  */
 public function delete($key)
 {
     if (!isset($this->pkey)) {
         $this->fetch_data();
     }
     if ($this->valid_key($key)) {
         $query = "DELETE FROM notes WHERE UID = ?";
         $handle = new Query($this->pdo, $query);
         $params = $this->members_to_array("UID");
         //I'm lazy
         $handle->exec($params);
         return $handle->success;
     }
     return self::E_INVALID_PKEY;
 }
Example #10
0
 function update()
 {
     $inscols = 'UPDATE `' . $this->table . '` SET ';
     foreach ($this->col as $c => $cc) {
         if (isset($this->_col[$c])) {
             if ($cc == 'NOW()') {
                 $inscols .= '`' . $c . '` = ' . $cc . ',';
             } else {
                 $inscols .= '`' . $c . '` = \'' . $cc . '\',';
             }
         }
     }
     $inscols = substr($inscols, 0, strlen($inscols) - 1);
     $q = new Query($this->db);
     $q->exec($inscols . ' WHERE ' . $this->field . ' = \'' . $this->vars . '\'');
 }
Example #11
0
            <li><a href="?action=upload">Upload File</a></li>
        </ul>
        <h2>Manage</h2>
        <ul>
            <li><a href="?action=manageuploads">Uploads</a></li>
            <li><a href="?action=manageposts">Posts</a></li>
            <li><a href="?action=manageoptions">Options</a></li>
        </ul>';
            break;
    }
} else {
    if (isset($_POST['username'])) {
        $success = false;
        $q = new Query($db);
        $q->exec('SELECT users.*
                  FROM users
                  WHERE users.username = \'' . $_POST['username'] . '\'
                  AND users.password = \'' . md5($_POST['password']) . '\'');
        if ($q->numrows > 0) {
            $success = true;
            $_SESSION['login'] = $q->data;
            $_SESSION['login']['password'] = '';
            // Security
        }
        $q->free();
        if ($success) {
            redirect('?rand=' . rand());
        }
    }
    $page_title = 'Login';
    $content = isset($success) && !$success ? 'Not Success. Sorry.' : '';
    $content .= '
Example #12
0
File: sql.php Project: hrn4n/argon
<?php

/*
 * Testing a few simple queries to see if the Query wrapper class works properly
 */
include "../src/core.php";
$query = new Query($pdo_link, "SELECT 2+2");
print_r($query->exec() == true);
$query->query = "CREATE TEMPORARY TABLE potatos (ID int PRIMARY KEY AUTO_INCREMENT, name varchar(20))";
print_r($query->exec() == true);
$testing = ['Juana', 'Maria', 'Pablo'];
$query->query = "INSERT INTO potatos (name) VALUES (?)";
foreach ($testing as $name) {
    print_r($query->exec([$name]) == true);
}
$query->query = "SELECT * FROM potatos";
print_r($query->exec() == true);
while ($row = $query->fetch()) {
    print_r(is_array($row) == true);
}
/*Output should look like this: 111111111*/
Example #13
0
/**
 * bool parseSql(string $text)
 *
 * Parses a SQL text
 *
 * @param string $text sentences to parse
 * @return bool false if an error occurs
 * @access public
 * @since 0.8
 */
function parseSql($text)
{
    $controlledErrors = array(1060, 1091);
    $installQ = new Query();
    $installQ->captureError(true);
    /**
     * reading through SQL text executing SQL only when ";" is encountered and if is out of brackets
     */
    $count = strlen($text);
    $sqlSentence = "";
    $outBracket = true;
    for ($i = 0; $i < $count; $i++) {
        $char = $text[$i];
        if ($char == "(") {
            $outBracket = false;
        }
        if ($char == ")") {
            $outBracket = true;
        }
        if ($char == ";" && $outBracket) {
            $result = $installQ->exec($sqlSentence);
            if ($installQ->isError() && !in_array($installQ->getDbErrno(), $controlledErrors)) {
                echo HTML::para(sprintf(_("Process sql [%s]"), $sqlSentence));
                $installQ->close();
                Error::query($installQ, false);
                echo Msg::error(sprintf(_("Error: %s"), $installQ->getDbError()));
                return false;
            }
            $sqlSentence = "";
        } else {
            $sqlSentence .= $char;
        }
    }
    $installQ->close();
    return true;
}