Ejemplo n.º 1
0
 function getExpressionTree($expr)
 {
     global $g_sqlSingleRecFuncs;
     $parser = new SqlParser($expr);
     $king_expr = new Expression();
     $current_expr =& $king_expr;
     while (!is_empty_str($elem = $parser->parseNextElementRaw())) {
         // function or IN / NOT IN?
         if (in_array(strtoupper($elem), $g_sqlSingleRecFuncs) || strtoupper($elem) == "IN" || strtoupper($elem) == "NOT IN") {
             $current_expr->expr_str .= $elem . " ";
             $elem = $parser->parseNextElementRaw();
             if ($elem != "(") {
                 print_error_msg("( expected after " . $current_expr->expr_str);
                 return null;
             }
             $current_expr->expr_str .= $elem;
             while (!is_empty_str($elem = $parser->parseNextElementRaw()) && $elem != ")") {
                 $current_expr->expr_str .= $elem;
             }
             $current_expr->expr_str .= $elem . " ";
             continue;
         }
         if ($elem == "(") {
             $current_expr->expr_str .= " % ";
             unset($new_expr);
             $new_expr = new Expression("");
             $current_expr->addChild($new_expr);
             $new_expr->setParent($current_expr);
             unset($current_expr);
             $current_expr =& $new_expr;
         } else {
             if ($elem == ")") {
                 unset($tmp);
                 $tmp =& $current_expr->getParent();
                 unset($current_expr);
                 $current_expr =& $tmp;
             } else {
                 // no spaces on .'s
                 if ($elem == ".") {
                     remove_last_char($current_expr->expr_str);
                     $current_expr->expr_str .= $elem;
                 } else {
                     $current_expr->expr_str .= $elem . " ";
                 }
             }
         }
     }
     return $king_expr;
 }
Ejemplo n.º 2
0
    exit;
}
$check_name_ndl = '';
if ($pha_nhom_duoc_ly_id != 0) {
    $check_name_ndl = new db_query('SELECT phg_name 
                                  FROM pharma_group 
                                  WHERE phg_id = "' . $pha_nhom_duoc_ly_id . '" 
                                  LIMIT 1');
    $check_name_ndl = mysqli_fetch_assoc($check_name_ndl->result);
    $check_name_ndl = $check_name_ndl['phg_name'];
}
#Phần hiển thị
$rainTpl = new RainTPL();
$rainTpl->assign('load_header', $load_header);
$rainTpl->assign('module_name', $module_name);
$rainTpl->assign('error_msg', print_error_msg($bg_errorMsg));
$html_page = '';
$form = new form();
$html_page .= $form->form_open();
$html_page .= $form->textnote('Các trường có dấu (<span class="form-asterick">*</span>) là bắt buộc nhập');
/**
 * something here
 */
$html_page .= $form->text(array('label' => 'Tên thuốc', 'name' => 'pha_name', 'id' => 'pha_name', 'value' => $pha_name, 'require' => 1, 'errorMsg' => 'Bạn chưa nhập tên thuốc', 'placeholder' => 'tên thuốc', 'isdatepicker' => 0, 'helpblock' => ''));
$html_page .= $form->text(array('label' => 'Tiêu đề thuốc', 'name' => 'pha_title', 'id' => 'pha_title', 'value' => $pha_title, 'require' => 1, 'errorMsg' => 'Bạn chưa nhập tiêu đề thuốc', 'placeholder' => 'tiêu đề thuốc', 'isdatepicker' => 0, 'helpblock' => ''));
$html_page .= $form->textarea(array('label' => 'Mô tả', 'name' => 'pha_description', 'id' => 'pha_description', 'value' => $pha_description, 'require' => 0, 'placeholder' => 'Mô tả thuốc', 'isdatepicker' => 0, 'helpblock' => ''));
$html_page .= $form->textarea(array('label' => 'Nội dung', 'name' => 'pha_content', 'id' => 'pha_content', 'value' => $pha_content, 'require' => 0, 'placeholder' => 'Nội dung thuốc', 'isdatepicker' => 0, 'helpblock' => ''));
$html_page .= $form->text(array('label' => 'Mã đăng ký', 'name' => 'pha_so_dang_ky', 'id' => 'pha_so_dang_ky', 'value' => $pha_so_dang_ky, 'require' => 1, 'placeholder' => 'Mã đăng ký', 'isdatepicker' => 0, 'helpblock' => ''));
$html_page .= $form->text(array('label' => 'Dạng bào chế', 'name' => 'pha_dang_bao_che', 'id' => 'pha_dang_bao_che', 'value' => $pha_dang_bao_che, 'require' => 1, 'placeholder' => 'Dạng bào chế', 'isdatepicker' => 0, 'helpblock' => ''));
$html_page .= $form->text(array('label' => 'Đóng gói', 'name' => 'pha_dong_goi', 'id' => 'pha_dong_goi', 'value' => $pha_dong_goi, 'require' => 0, 'placeholder' => 'Pha đóng gói', 'isdatepicker' => 0, 'helpblock' => ''));
$html_page .= $form->text(array('label' => 'Giá bán buôn', 'name' => 'pha_gia_buon', 'id' => 'pha_gia_buon', 'value' => $pha_gia_buon, 'require' => 0, 'placeholder' => '', 'isdatepicker' => 0, 'helpblock' => ''));
Ejemplo n.º 3
0
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="vi" lang="vi" xmlns:og="http://ogp.me/ns#" xmlns:fb="https://www.facebook.com/2008/fbml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php 
echo $load_header;
?>
</head>
<body>
<div class="module_header bold fix"><?php 
echo $module_name;
?>
</div>
<div id="wrapper">
    <?php 
print_error_msg($bg_errorMsg);
?>
	<?php 
$form = new form();
?>
    <script>
    var News = new News();
    </script>
	<?php 
echo $form->form_open();
?>
    <?php 
echo $form->textnote('Các trường có dấu (<span class="form-asterick">*</span>) là bắt buộc nhập');
?>
	
    <?php 
Ejemplo n.º 4
0
 function executeSelectQuery(&$sqlQuery)
 {
     global $g_sqlGroupingFuncs;
     global $g_sqlSingleRecFuncs;
     $resultSets = array();
     // create a copy
     $aliases = $sqlQuery->colAliases;
     $funcs = $sqlQuery->colFuncs;
     // Read all Tables
     for ($i = 0; $i < count($sqlQuery->tables); ++$i) {
         debug_printb("<br>[executeSelectQuery] Reading table " . $sqlQuery->tables[$i] . "<br>");
         if (!($resultSets[$i] = $this->readTable($sqlQuery->tables[$i]))) {
             print_error_msg("Reading Table " . $sqlQuery->tables[$i] . " failed");
             return false;
         }
         $resultSets[$i]->setColumnTableForAll($sqlQuery->tables[$i]);
         $resultSets[$i]->setColumnTableAliasForAll($sqlQuery->tableAliases[$i]);
         // set all functions to the ResultSet of the current table
         // if table and column name matches
         debug_printb("[executeSelectQuery] Setting functions for the current table:<br>");
         for ($j = 0; $j < count($funcs); ++$j) {
             if (!$funcs[$j] || !$sqlQuery->colNames[$j]) {
                 continue;
             }
             if ($sqlQuery->colTables[$j] == $sqlQuery->tables[$i] || $sqlQuery->colTables[$j] == $sqlQuery->tableAliases[$i]) {
                 $colNr = $resultSets[$i]->findColNrByAttrs($sqlQuery->colNames[$j], $sqlQuery->colTables[$j], "");
                 if ($colNr == NOT_FOUND) {
                     continue;
                 }
                 // create a new column for each function
                 $resultSets[$i]->addColumn($sqlQuery->colNames[$j], $sqlQuery->colAliases[$j], $sqlQuery->colTables[$j], "", "str", "", $funcs[$j], "", true);
                 $funcs[$j] = "";
             }
         }
         // set all aliases where table, column name and function matches
         debug_printb("[executeSelectQuery] Setting aliases for the current table:<br>");
         for ($j = 0; $j < count($aliases); ++$j) {
             if (!$aliases[$j]) {
                 continue;
             }
             if ($sqlQuery->colTables[$j] == $sqlQuery->tables[$i] || $sqlQuery->colTables[$j] == $sqlQuery->tableAliases[$i]) {
                 if (($colNr = $resultSets[$i]->findColNrByAttrs($sqlQuery->colNames[$j], $sqlQuery->colTables[$j], $sqlQuery->colFuncs[$j])) != NOT_FOUND) {
                     $resultSets[$i]->setColumnAlias($colNr, $aliases[$j]);
                     $aliases[$j] = "";
                 }
             }
         }
         if (TXTDBAPI_DEBUG) {
             debug_printb("<br>[executeSelectQuery] Dump of Table {$i} (" . $sqlQuery->tables[$i] . "):<br>");
             $resultSets[$i]->dump();
         }
     }
     // set remaining functions to the ResultSet where column name matches
     debug_printb("[executeSelectQuery] Setting remaining functions where column name matches:<br>");
     for ($i = 0; $i < count($resultSets); ++$i) {
         for ($j = 0; $j < count($funcs); ++$j) {
             if (!$funcs[$j] || !$sqlQuery->colNames[$j]) {
                 continue;
             }
             $colNr = $resultSets[$i]->findColNrByAttrs($sqlQuery->colNames[$j], "", "");
             if ($colNr == NOT_FOUND) {
                 // 'text' or 123 ? => add column
                 if (!(is_numeric($sqlQuery->colNames[$j]) || has_quotes($sqlQuery->colNames[$j]))) {
                     continue;
                 }
                 debug_print("Adding function with quoted string or number paremeter!<br>");
             }
             // create a new column for each function
             $resultSets[$i]->addColumn($sqlQuery->colNames[$j], $sqlQuery->colAliases[$j], $sqlQuery->colTables[$j], "", "str", "", $funcs[$j], "", true);
             $funcs[$j] = "";
         }
     }
     // set remaining aliases where column name and function matches
     debug_printb("[executeSelectQuery] Setting remaining aliases where column name and function matches:<br>");
     for ($i = 0; $i < count($resultSets); ++$i) {
         for ($j = 0; $j < count($aliases); ++$j) {
             if (!$aliases[$j]) {
                 continue;
             }
             if (($colNr = $resultSets[$i]->findColNrByAttrs($sqlQuery->colNames[$j], "", $sqlQuery->colFuncs[$j])) != NOT_FOUND) {
                 $resultSets[$i]->setColumnAlias($colNr, $aliases[$j]);
                 $aliases[$j] = "";
             }
         }
     }
     debug_printb("[executeSelectQuery] Executing single-rec functions (on the separate ResultSet's):<br>");
     // execute single-rec functions (on the separate ResultSet's)
     for ($i = 0; $i < count($resultSets); ++$i) {
         $resultSets[$i]->executeSingleRecFuncs();
     }
     // A query without tables ? => make a dummy ResultSet
     $dummyResultSet = false;
     if (count($sqlQuery->tables) == 0) {
         $dummyResultSet = true;
         $rsMaster = new ResultSet();
         $rsMaster->addColumn("(dummy)", "(dummy)", "(dummy)", "(dummy)", "str", "(dummy)", "", "", true);
         $rsMaster->append();
         // else: real ResultSet
     } else {
         $dummyResultSet = false;
         // join the ResultSet's
         $rsMaster = $resultSets[0];
         for ($i = 1; $i < count($resultSets); ++$i) {
             $rsMaster = $rsMaster->joinWithResultSet($resultSets[$i]);
         }
     }
     // from here we only work with $rsMaster and can free the other ResultSet's
     unset($resultSets);
     $resultSets = "";
     // generate additional columns for the remaining functions (functions without params)
     for ($i = 0; $i < count($funcs); ++$i) {
         if ($funcs[$i]) {
             $rsMaster->addColumn($sqlQuery->colNames[$i], $sqlQuery->colAliases[$i], "", "", "str", "", $funcs[$i], execFunc($funcs[$i], ""));
         }
     }
     // generate additional columns from the WHERE-expression
     $rsMaster->generateAdditionalColumnsFromWhereExpr($sqlQuery->where_expr);
     // generate additional columns from ORDER BY
     $rsMaster->generateAdditionalColumnsFromArray($sqlQuery->orderColumns);
     // generate additional columns from GROUP BY
     $rsMaster->generateAdditionalColumnsFromArray($sqlQuery->groupColumns);
     // execute the new single-rec functions (on the Master ResultSet)
     $rsMaster->executeSingleRecFuncs();
     // set row id's
     $rsMaster->reset();
     $rId = -1;
     while (++$rsMaster->pos < count($rsMaster->rows)) {
         $rsMaster->rows[$rsMaster->pos]->id = ++$rId;
     }
     --$rsMaster->pos;
     debug_printb("<br>[executeSelectQuery] Master ResultSet:</b><br>");
     if (TXTDBAPI_DEBUG) {
         $rsMaster->dump();
     }
     // apply WHERE expression
     if ($sqlQuery->where_expr) {
         $ep = new ExpressionParser();
         $rsMaster = $ep->getFilteredResultSet($rsMaster, $sqlQuery);
     }
     // free $ep
     unset($ep);
     $ep = "";
     // stop if the WHERE expression failed
     if (txtdbapi_error_occurred()) {
         return false;
     }
     // check if we can use some optimization
     // (use the limit in group by, but only if there are no grouping function
     // in the groupRows. To be able to do this we must order before grouping)
     $optimizedPath = true;
     if (!$sqlQuery->limit || !$sqlQuery->orderColumns) {
         $optimizedPath = false;
     } else {
         for ($i = 0; $i < count($sqlQuery->colFuncs); ++$i) {
             if (in_array($sqlQuery->colFuncs[$i], $g_sqlGroupingFuncs)) {
                 $optimizedPath = false;
                 break;
             }
         }
     }
     if ($optimizedPath) {
         debug_printb("[executeSelectQuery] Using optimized path!<br>");
     } else {
         debug_printb("[executeSelectQuery] Using normal path!<br>");
     }
     // Order ResultSet (if optimizedPath)
     if ($optimizedPath) {
         debug_printb("[executeSelectQuery] Calling orderRows() (optimized path)..<br>");
         if (count($sqlQuery->orderColumns) > 0) {
             $rsMaster->orderRows($sqlQuery->orderColumns, $sqlQuery->orderTypes);
         }
     }
     // Group ResultSet (process GROUP BY)
     $numGroupingFuncs = 0;
     for ($i = 0; $i < count($sqlQuery->colFuncs); ++$i) {
         if ($sqlQuery->colFuncs[$i] && in_array($sqlQuery->colFuncs[$i], $g_sqlGroupingFuncs)) {
             ++$numGroupingFuncs;
             break;
         }
     }
     if ($numGroupingFuncs > 0 || count($sqlQuery->groupColumns) > 0) {
         debug_printb("[executeSelectQuery] Calling groupRows()..<br>");
         $rsMaster = $rsMaster->groupRows($sqlQuery, $optimizedPath);
     }
     // Order ResultSet (if NOT optimizedPath)
     if (!$optimizedPath) {
         debug_printb("[executeSelectQuery] Calling orderRows() (normal path)..<br>");
         if (count($sqlQuery->orderColumns) > 0) {
             $rsMaster->orderRows($sqlQuery->orderColumns, $sqlQuery->orderTypes);
         }
     }
     // add direct value columns
     debug_printb("[executeSelectQuery] Adding direct value columns..<br>");
     for ($i = 0; $i < count($sqlQuery->colNames); ++$i) {
         if ($sqlQuery->colNames[$i] && (is_numeric($sqlQuery->colNames[$i]) || has_quotes($sqlQuery->colNames[$i])) && !$sqlQuery->colTables[$i] && !$sqlQuery->colFuncs[$i] && $rsMaster->findColNrByAttrs($sqlQuery->colNames[$i], "", "") == NOT_FOUND) {
             $value = $sqlQuery->colNames[$i];
             if (has_quotes($value)) {
                 remove_quotes($value);
             }
             $rsMaster->addColumn($sqlQuery->colNames[$i], $sqlQuery->colAliases[$i], "", "", "str", "", "", $value, true);
         }
     }
     // return only the requested columns
     debug_printb("[executeSelectQuery] Removing unwanted columns...<br>");
     $rsMaster->filterByColumnNamesInSqlQuery($sqlQuery);
     // order columns (not their data)
     debug_printb("[executeSelectQuery] Ordering columns (amog themself)...<br>");
     if (!$rsMaster->orderColumnsBySqlQuery($sqlQuery)) {
         print_error_msg("Ordering the Columns (themself) failed");
         return false;
     }
     // process DISTINCT
     if ($sqlQuery->distinct == 1) {
         $rsMaster = $rsMaster->makeDistinct($sqlQuery->limit);
     }
     // Apply Limit
     $rsMaster->reset();
     $rsMaster = $rsMaster->limitResultSet($sqlQuery->limit);
     verbose_debug_print("<br>Limited ResultSet:<br>");
     if (TXTDBAPI_VERBOSE_DEBUG) {
         $rsMaster->dump();
     }
     $rsMaster->reset();
     return $rsMaster;
 }
Ejemplo n.º 5
0
 function parseResultSetFromFileForAppend($fd)
 {
     $start = getmicrotime();
     $rs = new ResultSet();
     // COLUMN NAMES
     // read with a maximum of 1000 bytes, until there is a newline included (or eof)
     $buf = "";
     while (is_false(strstr($buf, "\n"))) {
         $buf .= fgets($fd, 1000);
         if (feof($fd)) {
             print_error_msg("Invalid Table File!<br>");
             return null;
         }
     }
     // remove newline
     remove_last_char($buf);
     $rec = $this->parseRowFromLine($buf);
     $rs->setColumnNames($rec);
     // COLUMN TYPES
     // read with a maximum of 1000 bytes, until there is a newline included (or eof)
     $buf = "";
     while (is_false(strstr($buf, "\n"))) {
         $buf .= fgets($fd, 1000);
         if (feof($fd)) {
             print_error_msg("Invalid Table File!<br>");
             return null;
         }
     }
     // remove newline
     remove_last_char($buf);
     $rec = $this->parseRowFromLine($buf);
     $rs->setColumnTypes($rec);
     // COLUMN DEFAULT VALUES
     // read with a maximum of 1000 bytes, until there is a newline included (or eof)
     $buf = "";
     while (is_false(strstr($buf, "\n"))) {
         $buf .= fgets($fd, 1000);
         if (feof($fd)) {
             break;
             // there's no newline after the colum types => empty table
         }
     }
     // remove newline
     if (last_char($buf) == "\n") {
         remove_last_char($buf);
     }
     $rec = $this->parseRowFromLine($buf);
     $rs->setColumnDefaultValues($rec);
     // get file size
     fseek($fd, 0, SEEK_END);
     $size = ftell($fd);
     $lastRecSize = min($size, ASSUMED_RECORD_SIZE);
     $lastRecPos = false;
     while (is_false($lastRecPos)) {
         fseek($fd, -$lastRecSize, SEEK_END);
         $buf = fread($fd, $lastRecSize);
         $lastRecSize = $lastRecSize * 2;
         $lastRecSize = min($size, $lastRecSize);
         if ($lastRecSize < 1) {
             print_error_message("lastRecSize should not be 0! Contact developer please!");
         }
         $lastRecPos = $this->getLastRecordPosInString($buf);
         if (TXTDBAPI_VERBOSE_DEBUG) {
             echo "<hr>pass! <br>";
             echo "lastRecPos: " . $lastRecPos . "<br>";
             echo "buf: " . $buf . "<br>";
         }
     }
     $buf = trim(substr($buf, $lastRecPos));
     verbose_debug_print("buf after substr() and trim(): " . $buf . "<br>");
     $rs->reset();
     $row = $this->parseRowFromLine($buf);
     if (TXTDBAPI_VERBOSE_DEBUG) {
         echo "parseResultSetFromFileForAppend(): last Row:<br>";
         print_r($row);
         echo "<br>";
     }
     $rs->appendRow($row);
     $rs->setColumnAliases(create_array_fill(count($rs->colNames), ""));
     $rs->setColumnTables(create_array_fill(count($rs->colNames), ""));
     $rs->setColumnTableAliases(create_array_fill(count($rs->colNames), ""));
     $rs->setColumnFunctions(create_array_fill(count($rs->colNames), ""));
     $rs->colFuncsExecuted = create_array_fill(count($rs->colNames), false);
     debug_print("<i>III: parseResultSetFromFileForAppend: " . (getmicrotime() - $start) . " seconds elapsed</i><br>");
     return $rs;
 }
Ejemplo n.º 6
0
 function test()
 {
     return true;
     // return true, function is outdated TODO: update
     reset($this->colNames);
     for ($i = 0; $i < count($this->colNames); ++$i) {
         if ($this->colNames[$i] == "*") {
             if ($this->colAliases[$i]) {
                 print_error_msg("Cannot define Alias by a *");
                 return FALSE;
             }
             continue;
         }
         if ($key = array_search($this->colNames[$i], $this->colNames)) {
             if ($i == $key) {
                 continue;
             }
             if ($this->colAliases[$i] == $this->colAliases[$key] && $this->colFuncs[$i] == $this->colFuncs[$key]) {
                 print_error_msg("Two Columns with the same name use no or the same alias ('" . $this->colNames[$i] . "', '" . $this->colNames[$key] . "')");
                 return FALSE;
             }
             if (!$this->colTables[$i]) {
                 print_error_msg("Column " . $this->colNames[$i] . " could belong to multiple Tables");
                 return FALSE;
             }
         }
     }
     reset($this->colAliases);
     for ($i = 0; $i < count($this->colAliases); ++$i) {
         if ($key = array_search($this->colAliases[$i], $this->colAliases)) {
             if ($i == $key || $this->colAliases[$i] == "") {
                 continue;
             }
             print_error_msg("Two Columns (" . $this->colNames[$i] . ", " . $this->colNames[$key] . ") use the same alias");
             return FALSE;
         }
     }
     reset($this->colNames);
     // TODO: error ..?!?  SELECT nr, tabelle1.nr As nr FROM ....
     // produces no Error !
     for ($i = 0; $i < count($this->colAliases); ++$i) {
         if ($key = array_search($this->colAliases[$i], $this->colNames)) {
             if ($i == $key) {
                 continue;
             }
             if ($this->colAliases[$i] == "") {
                 continue;
             }
             print_error_msg("Alias is the name from another column (" . $this->colAliases[$i] . ")");
             return FALSE;
         }
     }
     return TRUE;
 }
Ejemplo n.º 7
0
function txtdbapi_error_handler($errno, $errstr, $errfile, $errline)
{
    $prefix = "PHP Error: ";
    switch ($errno) {
        case E_USER_ERROR:
            print_error_msg($prefix . "FATAL [{$errno}] {$errstr} [Line: " . $errline . "] [File: " . $errfile . "]");
            break;
        default:
            print_error_msg($prefix . "[{$errno}] {$errstr} [Line: " . $errline . "] [File: " . $errfile . "]");
            break;
    }
}