function AddItemToSql($values) { if ($values['name'] == "") { throw new Exception("Musite vyplnit nazov"); } $sequence = dibi::fetchSingle("SELECT MAX(sequence) as max FROM menu_item WHERE parent=%i", $values['parent'], " ORDER BY sequence") + 1; if ($values['slug'] == "") { $values['slug'] = $values['name']; } $values['slug'] = $this->url_identifier($values['slug'], ''); if ($values['parent'] == NULL) { $values['parent'] = 0; } else { // $parent_url = self::getUrlIdentifier($values['parent']); } $collums = Tools::getCollum('menu_item'); foreach ($values as $k => $v) { if (!in_array($k, $collums)) { unset($values[$k]); } } $values['id_menu'] = $this->id_menu; dibi::query("INSERT INTO menu_item", $values); $id_menu_item = dibi::insertId(); // self::doSequence($values ['parent']); $this->repairUrls(); $this->pageModel->invalidateCache(); return $id_menu_item; }
public function add_new_article($article, $user_id) { $array = get_object_vars($article); $array["link_pdf"] = explode("/", $array["link_pdf"])[1]; //$array["link_pdf"] = $array["name"]; unset($array["name"]); dibi::query('INSERT INTO article', $array); $last_id = dibi::insertId(); $arr_owner = array("user_id_user" => $user_id, "article_id_article" => $last_id); dibi::query('INSERT INTO user_has_article', $arr_owner); }
static function createOrder($values, $id_product_params, $id_lang, $user) { dibi::begin(); // print_r($values);exit; dibi::query("INSERT INTO [order]", $values); $order_id = dibi::insertId(); foreach ($id_product_params as $id_product_param => $count) { self::insertProduct($id_product_param, $count, $order_id, $id_lang, $user); } dibi::commit(); return $order_id; }
public static function createUser(array $form) { $password = hash(HASH_TYPE, $form['password1']); dibi::query('INSERT INTO user ( `userName`, `password`, `time`, `firstName`, `surname`, `title`, `email`, `icq`, `skype`, `mobile`) VALUES (%s, %s, %i, %s, %s, %s, %s, %iN, %sN, %s)', $form['userName'], $password, time(), $form['firstName'], $form['surname'], $form['title'], $form['email'], (int) $form['icq'], $form['skype'], $form['mobile']); //Zjistíme id nově přidaného uživatele $id = dibi::insertId(); // Vložíme do tabulky userRole role nového uživatele foreach ($form['prava'] as $n => $row) { dibi::query('INSERT INTO userRole (userId, roleId, active) VALUES (%i, %i, 1)', $id, $row); } }
function duplicateNode($id_menu_item, $new_id_menu_item) { $sourceNode = dibi::fetchAll("SELECT * FROM [node] WHERE id_menu_item = %i", $id_menu_item); $node = new Node(); foreach ($sourceNode as $sn) { // $arr = array( // 'id_user' => $session['id_user'], // 'id_menu_item' => $_GET['id_menu_item'], // 'sequence' => $sequence, // 'id_type_modul' => $id_type_modul, // ); $tmp_id_node = $sn['id_node']; unset($sn['id_node']); $sn['id_menu_item'] = $new_id_menu_item; dibi::query("INSERT INTO node ", $sn); $last_id = dibi::insertId(); $node->nodeFactory($sn['id_type_modul'])->duplicate($tmp_id_node, $last_id); } }
public static function add($values) { dibi::query("INSERT INTO poll ", $values); return dibi::insertId(); }
public function insert($data) { $ua = array('username' => 1, 'role' => 1, 'password' => 1, 'active' => 1, 'id' => 1, 'name' => 1, 'surname' => 1, 'email' => 1, 'homepage' => 1, 'telephone' => 1, 'street' => 1, 'city' => 1, 'country' => 1, 'zip' => 1, 'icq' => 1, 'aim' => 1, 'jabber' => 1, 'skype' => 1, 'birthday' => 1, 'description' => 1, 'country_id' => 1, 'language_id' => 1, 'sex' => 1, 'created' => 1); if ($data['password'] != '') { $data['password'] = hash("sha512", $data['password'] . str_repeat('!@#$%^&*()_+_()*&^%$#@!', 10)); } $data['created'] = new DibiDateTime(); dibi::query('INSERT INTO [user]', array_intersect_key($data, $ua)); $data['id'] = dibi::insertId(); return $data['id']; }
function nodeAction() { $node = NodeModel::init(); //-------------------------------// //--------AJAX REQUEST-----------// //------------------------------// if (@$_GET['ajax_change_modul_position']) { if (is_numeric(@$_GET['id_node_ajax']) and is_numeric($_GET['position'])) { dibi::query("UPDATE node SET position=%i", $_GET['position'], " WHERE id_node=%i", $_GET['id_node_ajax']); $node->invalidateCache(); } exit; } if (@$_GET['ajax_change_modul_visible']) { if (is_numeric(@$_GET['id_node_ajax']) and is_numeric($_GET['modul_visible'])) { dibi::query("UPDATE node SET visible=%s", $_GET['modul_visible'], " WHERE id_node=%i", $_GET['id_node_ajax']); } $node->invalidateCache(); // echo dibi::$sql; exit; } //------SITE MAP pre premiestnenie modulu if (isset($_GET['ajax_show_site_map_for_modul'])) { $m = new MenuItem(); $m->doTreeSelectMoveModul(0, 0, $_GET['id_menu_item'], $_GET['id_type_modul']); echo '<form action="" method="post"> <select name="id_menu_item_for_change">'; echo $m->doTreeSelectMoveModulText; echo '<input type="hidden" name="id_type_modul" value="' . htmlspecialchars($_GET['id_type_modul']) . '" /> <input type="hidden" name="id_node" value="' . htmlspecialchars($_GET['id_node']) . '" /> <input type="submit" name="changeModulParent" value="Ulož" /> </form>'; exit; } if (isset($_POST['changeModulParent'])) { $this->changeModulParent(); $node->invalidateCache(); header("Location: ?id_menu_item=" . $_POST['id_menu_item_for_change'] . "&showModulsOnPage=1"); exit; } if (isset($_GET['id_menu_item']) and isset($_GET['id_type_modul']) and isset($_GET['id_modul'])) { if (!dibi::fetchSingle("SELECT COUNT(*) FROM node WHERE id_menu_item=%i", $_GET['id_menu_item'], " AND id_type_modul=%i", $_GET['id_type_modul'], " AND id_node=%i", $_GET['id_modul'])) { header("Location:admin.php"); exit; } } if (isset($_GET['addnode']) and isset($_GET['id_type_modul']) or isset($_POST['addModulToMenu'])) { if (isset($_POST['addModulToMenu'])) { $id_type_modul = $_POST['id_type_modul']; } else { $id_type_modul = $_GET['id_type_modul']; } $sequence = dibi::fetchSingle("SELECT MAX(sequence) FROM node WHERE id_menu_item=%i", $_GET['id_menu_item']) + 1; $session = NEnvironment::getSession('Authentication'); $config = NEnvironment::getConfig(); $arr = array('id_user' => NEnvironment::getUser()->getIdentity()->id, 'id_menu_item' => $_GET['id_menu_item'], 'sequence' => $sequence, 'id_type_modul' => $id_type_modul, 'visible' => $config['NODE_VISIBLE']); dibi::query("INSERT INTO node ", $arr); $this->addModul(dibi::insertId(), $id_type_modul); $node->invalidateCache(); } //zmenenie poradia if (isset($_GET['modul_id_up']) or isset($_GET['modul_id_down'])) { $this->changeOrderNode(); $node->invalidateCache(); header("Location: admin.php?id_menu_item=" . $_GET['id_menu_item'] . "&showModulsOnPage=1"); exit; } //ak je iba jeden modul, hned sa zobrazi ale iba ak nieje setnuta section a showModulsOnPage if (isset($_GET['id_menu_item']) and !isset($_GET['id_type_modul']) and !isset($_GET['section']) and !isset($_GET['showModulsOnPage']) and !isset($_GET['changeMenuItem'])) { $l = dibi::fetch("SELECT *, COUNT(*) as node_count FROM node WHERE id_menu_item=%i", $_GET['id_menu_item'], " ORDER BY sequence"); if ($l['node_count'] == 1) { header("Location: admin.php?id_menu_item=" . $_GET['id_menu_item'] . "&id_type_modul=" . $l['id_type_modul'] . "&id_modul=" . $l['id_node']); exit; } } //pridanie do premenej activeModul instanciu objektu if (isset($_GET['id_type_modul']) and isset($_GET['id_modul'])) { $this->activeModul = $this->nodeFactory($_GET['id_type_modul']); $this->activeModul->action(); } if (isset($_GET['id_modul_del']) and is_numeric($_GET['id_modul_del'])) { $this->deleteNode(NULL, $_GET['id_modul_del']); $node->invalidateCache(); header("Location: admin.php?id_menu_item=" . $_GET['id_menu_item']); exit; } }
public static function addPage($data) { //lang supplied in $data if (!isset($data['published'])) { $data['published'] = 0; } if (!isset($data['ord'])) { $data['ord'] = 1 + dibi::fetchSingle('SELECT max(ord) FROM pages WHERE lang=%s', $data['lang'], " AND id_parent=%s", $data['id_parent']); } dibi::query('INSERT INTO pages', $data); $new_page_id = dibi::insertId(); return $new_page_id; }
public function register(array $me) { exit; UserModel::insert(array('login' => $me['email'], 'fbuid' => $me['id'], 'name' => $me['first_name'], 'surname' => $me['last_name'], 'activate' => 1, 'password' => Tools::random(12), 'newsletter' => 0, 'iso' => 'SVK')); return UserModel::get(dibi::insertId()); }
public function addUser($form) { if ($form->isValid()) { $values = $form->getValues(); if (!isset($values['user_role'])) { $values['user_role'] = 0; } if (dibi::fetchSingle("SELECT 1 FROM auth_user WHERE login=%s", $values['login']) == 1) { throw new Exception("Dané prihlasovacie meno už existuje. Zadajte iné prosím."); } $arr = array('login' => $values['login'], 'password' => UserModel::getHash($values['password']), 'name' => $values['name'], 'surname' => $values['surname']); dibi::query("INSERT INTO auth_user", $arr); $last_id = dibi::insertId(); dibi::query("INSERT INTO [auth_user_role]", array('id_auth_user' => $last_id, 'id_auth_role' => $values['id_auth_role'])); Log::addLog($this, 'Pridanie noveho uzivatela'); } else { throw new Exception('Nespavne vyplneny formular'); } }
static function insert($values) { $user_value['name'] = @$values['name']; $user_value['surname'] = @$values['surname']; // $user_value['email'] = $values['email']; $user_value['login'] = $values['login']; $user_value['activate'] = $values['activate']; $user_value['password'] = self::getHash($values['password']); $user_value['fbuid'] = @$values['fbuid']; $user_value['google_id'] = @$values['google_id']; $user_value['newsletter'] = @$values['newsletter']; $user_value['discount'] = @$values['discount']; unset($values['name'], $values['surname'], $values['login'], $values['password'], $values['activate'], $values['fbuid'], $values['newsletter'], $values['discount']); dibi::begin(); dibi::insert(TABLE_USERS, $user_value)->execute(); $values['user_id'] = dibi::insertId(); dibi::insert(TABLE_USERS_INFO, $values)->execute(); dibi::commit(); return $values['user_id']; }
static function add($values) { $sequence = dibi::fetchSingle("SELECT sequence FROM [category]\n\t\t\tWHERE \n\t\t\t%if", $values['id_parent'] != '', "id_parent = %i", $values['id_parent'], "%else id_parent IS NULL %end ORDER BY sequence DESC"); $sequence++; $values['sequence'] = $sequence; if ($values['id_parent'] == '') { unset($values['id_parent']); } dibi::query("INSERT INTO [category]", $values); self::invalidateCache(); return dibi::insertId(); }
public function addFileNode($type_module, $id_module) { dibi::query("INSERT INTO [file_node]", array('type_module' => $type_module, 'id_module' => $id_module)); return dibi::insertId(); }
static function add($values) { $values['product_sequence'] = dibi::fetchSingle("SELECT MAX(product_sequence) + 1 FROM [product]"); dibi::query("INSERT INTO [product]", $values); return dibi::insertId(); }
public static function createNew($id_page, $path, $options = '') { //insert into database $pathinfo = pathinfo($path); $ord = 0; if ($options == 'end') { $ord = 1 + (int) dibi::fetchSingle('SELECT max(ord) FROM pages_files WHERE id_page=%i', $id_page, ' AND gallerynum=0'); } else { dibi::query('UPDATE pages_files SET ord=ord+1 WHERE id_page=%i', $id_page, ' AND gallerynum=0'); } dibi::query('INSERT INTO pages_files', array('id_page' => $id_page, 'filename' => $pathinfo['filename'], 'suffix' => isset($pathinfo['extension']) ? strtolower($pathinfo['extension']) : '', 'ord' => $ord)); //instance of File (or the specific file type) return self::getFile(dibi::insertId()); }