/** * Прямая или обратная связь? * * Примеры, * * Связь product -> product_info (OneToOne - product.id = product_info.product_id) * для product это обратная связь, для product_info прямая * * Связь product -> product_stat (OneToMany - product.id = product_stat.product_id) * для product это обратная связь, для product_info прямая * * Связь product -> tag через product_tag_link (ManyToMany) * для product это прямая свзяь, для tag обратная */ public function isDirect() { if ($this->getLinkTable()) { $localColumn = preg_replacE('#(^|_)id$#', '', $this->getLinkTableLocalColumn()); if (strpos($this->getLinkTable()->getName(), $localColumn) === 0) { return true; } else { return false; } } else { switch ($this->getLinkType()) { case self::LINK_TYPE_ONE_TO_ONE: return $this->getLocalColumn()->getName() != 'id'; break; case self::LINK_TYPE_ONE_TO_MANY: return false; break; case self::LINK_TYPE_MANY_TO_ONE: return true; break; } } }
<?php $sub_menu = '700600'; include_once './_common.php'; auth_check($auth[$sub_menu], "w"); $delete_suq_id = array(); $values = array(); $suq_sort = 0; for ($i = 0; $i <= $su_item_cnt; $i++) { $key = preg_replacE('/\\D/', '', $suq_sort_key[$i]); $suq_id = $_POST['_suq_id_' . $key]; $category = $_POST['_category_' . $key]; $type = $_POST['_type_' . $key]; $max_select = $_POST['_amax_' . $key]; $etc = $_POST['_etc_' . $key]; $question = $_POST['_q_' . $key]; $answer = $_POST['_a_' . $key]; if (empty($question)) { if ($suq_id) { $delete_suq_id[] = $suq_id; } continue; } $suq_sort++; $value = array('su_id' => $su_id, 'suq_id' => $suq_id, 'suq_sort' => $suq_sort, 'suq_category' => $category, 'suq_type' => $type, 'suq_max_select' => $max_select, 'suq_question' => $question, 'suq_enable_etc' => is_null($etc) ? 'disabled' : 'enabled'); for ($ak = 0; $ak < 10; $ak++) { $a = $answer[$ak]; $value['suq_answer_' . ($ak + 1)] = $a; } array_push($values, $value); }
protected function replaceVars($s) { $s = parent::replaceVars($s); if (preg_match('/^\\s*CREATE TABLE/i', $s)) { // CREATE TABLE hacks to allow schema file sharing with MySQL // binary/varbinary column type -> blob $s = preg_replace('/\\b(var)?binary(\\(\\d+\\))/i', 'blob\\1', $s); // no such thing as unsigned $s = preg_replace('/\\bunsigned\\b/i', '', $s); // INT -> INTEGER for primary keys $s = preg_replacE('/\\bint\\b/i', 'integer', $s); // No ENUM type $s = preg_replace('/enum\\([^)]*\\)/i', 'blob', $s); // binary collation type -> nothing $s = preg_replace('/\\bbinary\\b/i', '', $s); // auto_increment -> autoincrement $s = preg_replace('/\\bauto_increment\\b/i', 'autoincrement', $s); // No explicit options $s = preg_replace('/\\)[^)]*$/', ')', $s); } elseif (preg_match('/^\\s*CREATE (\\s*(?:UNIQUE|FULLTEXT)\\s+)?INDEX/i', $s)) { // No truncated indexes $s = preg_replace('/\\(\\d+\\)/', '', $s); // No FULLTEXT $s = preg_replace('/\\bfulltext\\b/i', '', $s); } return $s; }
public function preprocess() { global $FANNIE_OP_DB; $sql = FannieDB::get($FANNIE_OP_DB); /* ajax responses * $out is the output sent back * by convention, the request name ($_GET['action']) * is prepended to all output so the javascript receiver * can handle responses differently as needed. * a backtick separates request name from data */ $out = ''; if (isset($_GET['action'])) { // prepend request name & backtick $out = $_GET['action'] . "`"; // switch on request name switch ($_GET['action']) { case 'additem': $item = $_GET['item']; $orderno = $_GET['orderno']; $units = $this->strim($_GET['units']); $price = $_GET['price']; $price = preg_replace("/,/", ".", $price); $size = $_GET['size']; $cases = $this->strim($_GET['cases']); $fraction = $this->strim($_GET['fraction']); $category = $this->strim($_GET['category']); $category = preg_replace("/_/", " ", $category); if (empty($price)) { $price = 0; } if (empty($cases)) { $cases = 0; } if (empty($fraction)) { $fraction = 0; } $stocktotal = 0; if (!empty($units)) { if ($units[strlen($units) - 1] == '#' && $fraction[strlen($fraction) - 1] == '#' && $units != 0) { $partial = substr($fraction, 0, strlen($fraction) - 1) / substr($units, 0, strlen($units) - 1); $stocktotal = $cases + $partial; } else { if ($units != 0) { $partial = $fraction / $units; $stocktotal = $cases + $partial; } } } $total = $stocktotal * $price; $model = new DeliInventoryCatModel($sql); $model->item($item); $model->orderno($orderno); $model->units($units); $model->cases($cases); $model->fraction($fraction); $model->totalstock($stocktotal); $model->price($price); $model->total($total); $model->size($size); $model->category($category); $model->save(); $out .= $this->gettable(); break; case 'saveitem': $id = $_GET["id"]; $item = $this->strim($_GET['item']); $orderno = $this->strim($_GET['orderno']); $units = $this->strim($_GET['units']); $cases = $this->strim($_GET['cases']); $fraction = $this->strim($_GET['fraction']); $price = $this->strim($_GET['price']); $size = $this->strim($_GET['size']); if (empty($cases) || !is_numeric($cases)) { $cases = 0; } if (empty($fraction)) { $fraction = 0; } $stocktotal = 0; if (!empty($units)) { if ($units[strlen($units) - 1] == '#' && $fraction[strlen($fraction) - 1] == '#' && $units != 0) { $partial = substr($fraction, 0, strlen($fraction) - 1) / substr($units, 0, strlen($units) - 1); $stocktotal = $cases + $partial; } else { if ($units != 0) { $partial = $fraction / $units; $stocktotal = $cases + $partial; } } } $total = $stocktotal * $price; $model = new DeliInventoryCatModel($sql); $model->id($id); $model->item($item); $model->orderno($orderno); $model->units($units); $model->cases($cases); $model->fraction($fraction); $model->totalstock($stocktotal); $model->price($price); $model->total($total); $model->size($size); $model->save(); $ret = array('stock' => $stocktotal, 'total' => $total, 'cat' => str_replace(' ', '_', $model->category())); // recalculate category total $cat = $model->category(); $model->reset(); $model->category($cat); $ret['grandTotal'] = 0.0; foreach ($model->find() as $obj) { $ret['grandTotal'] += $obj->total(); } echo json_encode($ret); $out = ''; break; case 'refresh': $out .= $this->gettable(); break; case 'deleteitem': $id = $_GET['id']; $model = new DeliInventoryCatModel($sql); $model->id($id); $cat = $model->category(); $model->delete(); $ret = array('delete_row' => True); $model->reset(); $model->category($cat); $remaining = $model->find(); if (count($remaining) == 0) { $ret['delete_category'] = str_replace(' ', '_', $cat); } echo json_encode($ret); $out = ''; break; case 'printview': $category = $_GET['category']; $out = ""; if (isset($_GET["excel"])) { header("Content-Disposition: inline; filename=deliInventoryCat.xls"); header("Content-Description: PHP3 Generated Data"); header("Content-type: application/vnd.ms-excel; name='excel'"); } else { $out .= "<a href={$_SERVER['PHP_SELF']}?action=printview&category={$category}&excel=yes>Save to Excel</a><br />"; } $out .= $this->gettable(true, $category); break; case 'saveCategory': $oldcat = preg_replace("/_/", " ", $_GET['oldcat']); $newcat = preg_replacE("/_/", " ", $_GET['newcat']); $update = $sql->prepare_statement('UPDATE deliInventoryCat SET category=? WHERE category=?'); $sql->exec_statement($update, array($newcat, $oldcat)); $out .= $this->gettable(); break; case 'catList': $id = $_GET['id']; $cat = preg_replace("/_/", " ", $_GET['category']); $fetchQ = "select category from deliInventoryCat\n group by category order by category"; $fetchR = $sql->query($fetchQ); $out .= "{$id}" . "`"; $out .= "<select onchange=\"saveCat({$id});\" id=catSelect{$id}>"; while ($fetchW = $sql->fetch_array($fetchR)) { if ($fetchW[0] == $cat) { $out .= "<option selected>{$fetchW['0']}</option>"; } else { $out .= "<option>{$fetchW['0']}</option>"; } } $out .= "</select>"; break; case 'changeCat': $id = $_GET['id']; $newcat = $_GET['newcat']; $model = new DeliInventoryCatModel($sql); $model->id($id); $model->category($newcat); $model->save(); $model->reset(); $model->category($newcat); $ret['grandTotal'] = 0.0; foreach ($model->find() as $obj) { $ret['grandTotal'] += $obj->total(); } echo json_encode($ret); break; case 'clearAll': $clearQ = "update deliInventoryCat set cases=0, fraction=0,\n totalstock=0, total=0"; $clearR = $sql->query($clearQ); $out .= $this->gettable(); break; } echo $out; return false; } else { return true; } }