| 1 |
<?php |
|---|
| 2 |
defined('_VALID_MOS') or die('Direct Access to this location is not allowed.'); |
|---|
| 3 |
setlocale(LC_CTYPE, 'ru_RU.UTF-8'); |
|---|
| 4 |
mb_internal_encoding('UTF-8'); |
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
class tbAutoName extends mosDBTable { |
|---|
| 8 |
var $name = ''; |
|---|
| 9 |
var $correct = 0; |
|---|
| 10 |
|
|---|
| 11 |
function tbAutoName($table, $key, &$_db) { |
|---|
| 12 |
$this->mosDBTable($table ,$key, $_db); |
|---|
| 13 |
} |
|---|
| 14 |
|
|---|
| 15 |
function add($name) { |
|---|
| 16 |
if (!$this->check($name)) return false; |
|---|
| 17 |
$name = str_replace("'", "''", $name); |
|---|
| 18 |
$query = "INSERT INTO `$this->_tbl`(`name`) VALUES(UPPER('$name'));"; |
|---|
| 19 |
$this->_db->setQuery($query); |
|---|
| 20 |
if(!$this->_db->query()) { |
|---|
| 21 |
echo $this->_db->stderr(); |
|---|
| 22 |
return false; |
|---|
| 23 |
} |
|---|
| 24 |
return true; |
|---|
| 25 |
} |
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
function check($name) { |
|---|
| 29 |
if(empty($name)) return false; |
|---|
| 30 |
$name = str_replace("'", "''", $name); |
|---|
| 31 |
$where_q = "WHERE $this->_tbl_key = UPPER('$name')"; |
|---|
| 32 |
$query = "SELECT COUNT(*) FROM $this->_tbl $where_q LIMIT 1"; |
|---|
| 33 |
$this->_db->setQuery($query); |
|---|
| 34 |
$cnt = $this->_db->loadResult(); |
|---|
| 35 |
if(!$this->_db->query()) { |
|---|
| 36 |
echo $this->_db->stderr(); |
|---|
| 37 |
return false; |
|---|
| 38 |
} |
|---|
| 39 |
if($cnt == 0) |
|---|
| 40 |
return true; |
|---|
| 41 |
|
|---|
| 42 |
return false; |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
function blocked($name) { |
|---|
| 47 |
if(empty($name)) return true; |
|---|
| 48 |
$name = str_replace("'", "''", $name); |
|---|
| 49 |
$where_q = "WHERE $this->_tbl_key = UPPER('$name') AND correct=2"; |
|---|
| 50 |
$query = "SELECT COUNT(*) FROM $this->_tbl $where_q LIMIT 1"; |
|---|
| 51 |
$this->_db->setQuery($query); |
|---|
| 52 |
$cnt = $this->_db->loadResult(); |
|---|
| 53 |
if(!$this->_db->query()) { |
|---|
| 54 |
echo $this->_db->stderr(); |
|---|
| 55 |
return true; |
|---|
| 56 |
} |
|---|
| 57 |
if($cnt == 0) |
|---|
| 58 |
return false; |
|---|
| 59 |
|
|---|
| 60 |
return true; |
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
function suggest($name) { |
|---|
| 65 |
if (empty($name)) return array(); |
|---|
| 66 |
$name = str_replace("'", "''", $name); |
|---|
| 67 |
$where_q = "WHERE $this->_tbl_key LIKE UPPER('$name%') AND correct<>2"; |
|---|
| 68 |
$order_q = "ORDER BY $this->_tbl_key"; |
|---|
| 69 |
|
|---|
| 70 |
$query = "SELECT * FROM $this->_tbl $where_q $order_q LIMIT 10"; |
|---|
| 71 |
$this->_db->setQuery($query); |
|---|
| 72 |
$rows = $this->_db->loadRowList(); |
|---|
| 73 |
$res = array(); |
|---|
| 74 |
foreach($rows as $row) { |
|---|
| 75 |
array_push($res, mb_convert_case($row["name"], MB_CASE_TITLE, 'UTF-8')); |
|---|
| 76 |
} |
|---|
| 77 |
if (!$this->_db->query()) { |
|---|
| 78 |
echo $this->_db->stderr(); |
|---|
| 79 |
return array(); |
|---|
| 80 |
} |
|---|
| 81 |
return $res; |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
function listUnchecked() { |
|---|
| 88 |
$where_q = "WHERE correct=0"; |
|---|
| 89 |
$order_q = "ORDER BY $this->_tbl_key"; |
|---|
| 90 |
|
|---|
| 91 |
$query = "SELECT * FROM $this->_tbl $where_q $order_q"; |
|---|
| 92 |
$this->_db->setQuery($query); |
|---|
| 93 |
$rows = $this->_db->loadRowList(); |
|---|
| 94 |
$res = array(); |
|---|
| 95 |
$rows as $row) { |
|---|
| 96 |
array_push($res, |
|---|
| 97 |
"name" => mb_convert_case($row["name"], MB_CASE_TITLE, 'UTF-8'), |
|---|
| 98 |
"correct" => $row["correct"])); |
|---|
| 99 |
|
|---|
| 100 |
$this->_db->query()) { |
|---|
| 101 |
$this->_db->stderr(); |
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
$res; |
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
listAll() { |
|---|
| 108 |
$order_q = "ORDER BY $this->_tbl_key"; |
|---|
| 109 |
|
|---|
| 110 |
$query = "SELECT * FROM $this->_tbl $order_q"; |
|---|
| 111 |
$this->_db->setQuery($query); |
|---|
| 112 |
$rows = $this->_db->loadRowList(); |
|---|
| 113 |
$res = array(); |
|---|
| 114 |
$rows as $row) { |
|---|
| 115 |
array_push($res, |
|---|
| 116 |
"name" => mb_convert_case($row["name"], MB_CASE_TITLE, 'UTF-8'), |
|---|
| 117 |
"correct" => $row["correct"])); |
|---|
| 118 |
|
|---|
| 119 |
$this->_db->query()) { |
|---|
| 120 |
$this->_db->stderr(); |
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
$res; |
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
accept($names) { |
|---|
| 127 |
$names)) return; |
|---|
| 128 |
$names as $n) { |
|---|
| 129 |
$n = str_replace("'", "''", $n); |
|---|
| 130 |
$req = "UPDATE $this->_tbl SET correct=1 WHERE $this->_tbl_key=UPPER('$n') LIMIT 1;"; |
|---|
| 131 |
$this->_db->setQuery($req); |
|---|
| 132 |
$this->_db->query()) { |
|---|
| 133 |
$this->_db->stderr(); |
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
block($names) { |
|---|
| 139 |
$names)) return; |
|---|
| 140 |
$names as $n) { |
|---|
| 141 |
$n = str_replace("'", "''", $n); |
|---|
| 142 |
$req = "UPDATE $this->_tbl SET correct=2 WHERE $this->_tbl_key=UPPER('$n') LIMIT 1;"; |
|---|
| 143 |
$this->_db->setQuery($req); |
|---|
| 144 |
$this->_db->query()) { |
|---|
| 145 |
$this->_db->stderr(); |
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
uncheck($names) { |
|---|
| 151 |
$names)) return; |
|---|
| 152 |
$names as $n) { |
|---|
| 153 |
$n = str_replace("'", "''", $n); |
|---|
| 154 |
$req = "UPDATE $this->_tbl SET correct=null WHERE $this->_tbl_key = UPPER('$n') LIMIT 1;"; |
|---|
| 155 |
$this->_db->setQuery($req); |
|---|
| 156 |
$this->_db->query()) { |
|---|
| 157 |
$this->_db->stderr(); |
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
remove($names) { |
|---|
| 163 |
$names)) return; |
|---|
| 164 |
$names as $n) { |
|---|
| 165 |
$n = str_replace("'", "''", $n); |
|---|
| 166 |
$req = "DELETE FROM $this->_tbl WHERE $this->_tbl_key=UPPER('$n') LIMIT 1;"; |
|---|
| 167 |
$this->_db->setQuery($req); |
|---|
| 168 |
$this->_db->query()) { |
|---|
| 169 |
$this->_db->stderr(); |
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 |
?> |
|---|
| 175 |
|
|---|