fetchAll() public static method

Executes SQL query and fetch results - Monostate for Dibi\Connection::query() & fetchAll().
public static fetchAll ( $args ) : Dibi\Row[]
return Dibi\Row[]
Beispiel #1
0
 function __construct()
 {
     //-----vytvorenie objektu menu
     $menu = new MenuItem();
     $menu->menuAction();
     //-----vytvorenie objektu node
     $node = new node();
     $node->nodeAction();
     MT::addContent($menu->render(), 'leftHolder');
     try {
         if (isset($_GET['id_menu_item']) or isset($_GET['addMenuItem']) or isset($_GET['changeMenuItem'])) {
             MT::addTemplate(APP_DIR . '/templates/admin/modulHolder.phtml', 'modulHolder');
             MT::addVar('modulHolder', 'type_modul', dibi::fetchAll("SELECT * FROM [type_modul] WHERE visible_for_user='******'"));
         }
         //zobrazenie zmeny polozky pre menu
         if (isset($_GET['changeMenuItem'])) {
             $menu->showChangeMenuItem($_GET['id_menu_item']);
         }
         if (isset($_GET['id_menu_item']) and !isset($_GET['changeMenuItem'])) {
             $node->showModul();
         }
         //pridanie polozky do menu
         if (isset($_GET['addMenuItem'])) {
             $menu->showAddMenuItem();
         }
         //zachytenie vynimie
     } catch (NodeException $e) {
         echo '<div style="border: 2px solid red; padding: 5px;">' . $e->getMessage() . '</div>';
         exit;
     }
 }
Beispiel #2
0
 protected function createComponentAddEdit($name)
 {
     $form = new NAppForm($this, $name);
     $access = array(1 => 'Allow', 0 => 'Deny');
     // roles
     $mroles = new RolesModel();
     $roles = $mroles->getTreeValues();
     // resources
     $resources[0] = '- All resources -';
     $mresources = new ResourcesModel();
     $rows = $mresources->getTreeValues();
     foreach ($rows as $key => $row) {
         // function array_merge does't work correctly with integer indexes
         // manual array merge
         $resources[$key] = $row;
     }
     // privileges
     $privileges[0] = '- All privileges -';
     $rows = dibi::fetchAll('SELECT id, name FROM [gui_acl_privileges] ORDER BY name;');
     foreach ($rows as $row) {
         // function array_merge does't work correctly with integer indexes
         // manual array merge
         $privileges[$row->id] = $row->name;
     }
     //$renderer = $form->getRenderer();
     //$renderer->wrappers['label']['suffix'] = ':';
     //$form->addGroup('Add');
     $form->addMultiSelect('role_id', 'Role', $roles, 15)->addRule(NForm::FILLED, 'You have to fill roles.');
     $form->addMultiSelect('resource_id', 'Resources', $resources, 15)->addRule(NForm::FILLED, 'You have to fill resources.');
     $form->addMultiSelect('privilege_id', 'Privileges', $privileges, 15)->addRule(NForm::FILLED, 'You have to fill privileges.');
     //$form->addSelect('access', 'Access', $access)
     $form->addRadioList('access', 'Access', $access)->addRule(NForm::FILLED, 'You have to fill access.');
     $form->addSubmit('assign', 'Assign');
     $form->onSuccess[] = array($this, 'addEditOnFormSubmitted');
 }
    function renderXml()
    {
        //$this->id_lang
        $list = dibi::fetchAll('
				SELECT 
				product.id_product
				FROM 
					`product`					
					JOIN category_product USING (id_product)					
					JOIN category USING (id_category)
				WHERE 
					product.active = 1 AND					
					product.added = 1 AND
					category.active = 1				
				
				GROUP BY (id_product)');
        $this->template->baseUri = 'http://' . $_SERVER['HTTP_HOST'];
        $this->id_lang = 1;
        $this->template->items = array();
        foreach ($list as $k => $l) {
            $this->template->items[$k] = ProductModel::getProductWithParams($l['id_product'], $this->id_lang, NULL);
            $this->template->items[$k]['url'] = $this->link(':Front:Product:default', array('id' => $l['id_product'], 'id_category' => $this->template->items[$k]['main_category']));
            //zisti nazvy kategorii
            $category = array();
            foreach ($this->template->items[$k]['categories'] as $cat) {
                $tmp = CategoryModel::get($cat['id_category'], $this->id_lang);
                $category[] = $tmp['name'];
            }
            $this->template->items[$k]['categories_name'] = implode(" | ", $category);
        }
        //		dde($this->template->items);
    }
Beispiel #4
0
 static function get($id_order, $id_user = null)
 {
     $order = dibi::fetch("SELECT * FROM [order] WHERE id_order = %i", $id_order, "%if", $id_user != null, "AND id_user = %i", $id_user, "AND deleted = 0 %end");
     if (!empty($order)) {
         $order['products'] = dibi::fetchAll("SELECT * FROM [order_product] WHERE id_order = %i", $id_order);
     }
     return $order;
 }
Beispiel #5
0
 public function add_reviewer($id_article, $id_user)
 {
     $res = dibi::fetchAll("SELECT article_id_article,user_id_user FROM review" . " WHERE user_id_user =%s" . " AND article_id_article = %s", $id_user, $id_article);
     if ($res) {
         return false;
     } else {
         $array = array('article_id_article' => $id_article, 'user_id_user' => $id_user);
         dibi::query('INSERT INTO review', $array);
         return true;
     }
 }
Beispiel #6
0
 function renderList($categories)
 {
     $this->template->blog_box = dibi::fetchAll("SELECT * FROM `menu_item` \nLEFT JOIN node USING (id_menu_item)\nLEFT JOIN article USING (id_node)\nWHERE \nmenu_item.url_identifier = %s", $categories, "\nORDER BY id_node DESC\n");
     foreach ($this->template->blog_box as $article) {
         $article['url'] = $this->getPresenter()->link('Blog:current', array('categories' => $categories, 'url_identifier' => $article->url_identifier));
         if ($image = FilesNode::getOneFirstFile('article', $article->id_node)) {
             $article['image_url'] = Files::gURL($image->src, $image->ext, 220, 160, 6);
         }
     }
     $session = NEnvironment::getSession("Front_List");
     $session['back_url'] = $_SERVER['REQUEST_URI'];
 }
 static function findBests()
 {
     try {
         return dibi::fetchAll("SELECT * FROM [article] WHERE [best]");
     } catch (DibiDriverException $e) {
         // tady dalsi zjistovani, zda se jedna o kritickou chybu
         // switch ($e->getCode())
         if (11 == $e->getCode()) {
             // tabulka je poskozena (zde se jedna o poskozeny soubor, melo by to normalne shodit cely web, ale neudelam tak)
             return array();
         } else {
             throw $e;
         }
     }
     // samotnou DibiException necham vybublat
 }
Beispiel #8
0
 function render($id_poll = NULL)
 {
     if ($id_poll == NULL) {
         $id_poll = $this->id_poll;
     }
     $template = $this->template;
     $template->setFile(dirname(__FILE__) . '/poll.phtml');
     $template->l = dibi::fetch("SELECT * FROM poll WHERE id_poll=%i", $id_poll, " AND from_date <= CURRENT_DATE() AND to_date >= CURRENT_DATE()");
     $template->answer = dibi::fetchAll("SELECT *, (SELECT COUNT(id_poll_ip_vol) FROM poll_ip_vol WHERE id_poll_answer = poll_answer.id_poll_answer) AS c FROM poll_answer WHERE id_poll=%i", $id_poll, "ORDER BY sequence");
     $template->answer_count = 0;
     //spocita iba tie co uz maju vysledok
     foreach ($template->answer as $a) {
         $template->answer_count += $a['c'];
     }
     $template->render();
 }
Beispiel #9
0
 function handleChangePrice(NFORM $form)
 {
     $values = $form->getValues();
     $id_category = $this->getParam('id_category');
     $coeficient = $values['coeficient'];
     if (!is_numeric($id_category)) {
         $form->addError('Nie je vybraná kategória');
         return $form;
     }
     if ($coeficient == 0) {
         $form->addError('Koeficient nesmie byť nula.');
         return $form;
     }
     $list = dibi::fetchAll("\n\t\t\t\tSELECT\n\t\t\t\tproduct_param.id_product_param,\n\t\t\t\tproduct_param.price\n\t\t\t\tFROM\n\t\t\t\t\t[category_product]\n\t\t\t\t\tJOIN [product_param] USING(id_product)\n\t\t\t\tWHERE\n\t\t\t\t\tid_category = %i", $id_category);
     foreach ($list as $l) {
         $arr = array('price' => round($l['price'] * $coeficient));
         dibi::query("UPDATE [product_param] SET ", $arr, "WHERE id_product_param = %i", $l['id_product_param']);
     }
 }
Beispiel #10
0
 /**
  * @param array Array of roles
  */
 public function __construct($roles)
 {
     $resources = dibi::fetchAll('SELECT key_name, name FROM [' . TABLE_RESOURCES . '] ORDER BY name;');
     $privileges = dibi::fetchAll('SELECT key_name, name FROM [' . TABLE_PRIVILEGES . '] ORDER BY name;');
     $acl = new Acl();
     $i = 0;
     foreach ($resources as $res) {
         foreach ($privileges as $pri) {
             foreach ($roles as $role) {
                 if ($acl->isAllowed($role->key_name, $res->key_name, $pri->key_name)) {
                     $this->access[$i]['resource'] = $res->name;
                     $this->access[$i]['privileg'] = $pri->name;
                     $i++;
                     break 1;
                 }
             }
         }
     }
 }
Beispiel #11
0
 /**
  * @param array Array of roles
  */
 public function __construct($roles)
 {
     $resources = dibi::fetchAll('SELECT key_name, name FROM [' . self::ACL_RESOURCES_TABLE . '] ORDER BY name;');
     $privileges = dibi::fetchAll('SELECT key_name, name FROM [' . self::ACL_PRIVILEGES_TABLE . '] ORDER BY name;');
     $acl = new Acl();
     $i = 0;
     foreach ($resources as $res) {
         foreach ($privileges as $pri) {
             foreach ($roles as $role) {
                 if (@$acl->isAllowed($role->key_name, $res->key_name, $pri->key_name)) {
                     // @ to repress NOTICE if assertion required and resource property (id, owner_id, ...) not set yet
                     $this->access[$i]['resource'] = $res->name;
                     $this->access[$i]['privileg'] = $pri->name;
                     $i++;
                     break 1;
                 }
             }
         }
     }
 }
Beispiel #12
0
 function changeOrderNode()
 {
     $order = 'DESC';
     if (isset($_GET['modul_id_up'])) {
         $id_node = $_GET['modul_id_up'];
     }
     if (isset($_GET['modul_id_down'])) {
         $id_node = $_GET['modul_id_down'];
     }
     $pom = dibi::fetch("SELECT sequence,id_node,id_menu_item FROM node WHERE id_node=%i", $id_node, " LIMIT 1 ");
     if (isset($_GET['modul_id_up'])) {
         $sequence = $pom['sequence'] + 1.5;
     }
     if (isset($_GET['modul_id_down'])) {
         $sequence = $pom['sequence'] - 1.5;
     }
     //	print_r($pom);
     dibi::query("UPDATE node SET sequence=%s", $sequence, "WHERE id_node=%i", $id_node);
     //	echo dibi::$sql;
     //oprava poradia
     $list = dibi::fetchAll("SELECT * FROM node WHERE id_menu_item='" . $pom['id_menu_item'] . "' ORDER BY sequence");
     $sequence = 0;
     //	echo dibi::$sql;
     //	print_r($list);
     //	exit;
     //	exit;
     foreach ($list as $l) {
         ++$sequence;
         dibi::query("UPDATE node SET sequence=%i", $sequence, " WHERE id_node=%i", $l['id_node']);
     }
     //	exit;
 }
Beispiel #13
0
 function beforeRender()
 {
     //self::parseSparksCSV();
     //	ProductModel::repairSequenceProductParam();exit;
     $cache = NEnvironment::getCache('parse_xml');
     $this->all_product_param_db = dibi::query("SELECT code,id_product FROM [product_param]")->fetchPairs('code', 'id_product');
     $this->all_product_db = dibi::query("SELECT group_code,id_product FROM [product]")->fetchPairs('group_code', 'id_product');
     $this->all_categories_db = dibi::fetchAll("SELECT id_category,name,id_parent FROM [category] JOIN [category_lang] USING(id_category) WHERE id_lang = 1");
     //		print_r($this->all_categories_db);
     //zisti levely
     $category_1 = array();
     $category_2 = array();
     $category_3 = array();
     foreach ($this->all_categories_db as $k => $c) {
         //prvy
         if ($c['id_parent'] == NULL) {
             $this->all_categories_db[$k]['level'] = 0;
             $category_1[$c['id_category']] = $c['name'];
         }
     }
     foreach ($this->all_categories_db as $k => $c) {
         //prvy
         if ($c['id_parent'] != NULL) {
             foreach ($this->all_categories_db as $k1 => $c1) {
                 if ($c1['id_category'] == $c['id_parent']) {
                     if ($this->all_categories_db[$k1]['level'] == 0) {
                         $this->all_categories_db[$k]['level'] = 1;
                         $category_2[$c['id_category']] = $c['name'];
                     }
                 }
             }
         }
     }
     foreach ($this->all_categories_db as $k => $c) {
         if (!isset($c['level'])) {
             $this->all_categories_db[$k]['level'] = 2;
             $category_3[$c['id_category']] = $c['name'];
         }
     }
     $this->category_1 = $category_1;
     $this->category_2 = $category_2;
     $this->category_3 = $category_3;
     // stiahni a rozzipuj subor
     //		$link
     $zip_file_name = WWW_DIR . "/uploaded/xml/xml.zip";
     if (isset($cache['xml_file_name'])) {
         $xml_file = $cache['xml_file_name'];
     } else {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, 'http://www.sparks.sk/product/xml/SparksProducts.zip');
         curl_setopt($ch, CURLOPT_HEADER, false);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         $zip = curl_exec($ch);
         curl_close($ch);
         $fp = fopen($zip_file_name, "w");
         fwrite($fp, $zip);
         fclose($fp);
         $archive = new PclZip($zip_file_name);
         $list = $archive->extract(WWW_DIR . '/uploaded/xml/');
         if ($list[0]['status'] != 'ok') {
             throw new Exception('Nastala chyba pri rozbalovani suboru: ' . $list[0]['stored_filename']);
         }
         $cache->save('xml_file_name', $list[0]['stored_filename'], array('expire' => time() + 60 * 1));
         $xml_file = $list[0]['stored_filename'];
     }
     $myXMLString = file_get_contents(WWW_DIR . '/uploaded/xml/' . $xml_file);
     $myXMLString = iconv('UTF-8', 'windows-1250', $myXMLString);
     $doc = new DOMDocument('1.0', 'windows-1250');
     $doc->loadXML($myXMLString);
     $x = $doc->documentElement;
     $c = 0;
     foreach ($x->childNodes as $item) {
         $product = array();
         foreach ($item->childNodes as $i) {
             $node_value = preg_replace('#!\\[CDATA\\[#', '', $i->nodeValue);
             $node_value = preg_replace('#\\]\\]#', '', $node_value);
             //				$product[$i->nodeName] = iconv("UTF-8",'ISO-8859-2', $node_value);;
             $product[$i->nodeName] = $node_value;
         }
         //if($c>4000)print_r($product);
         $this->add($product);
         if (++$c > 5000) {
             throw new Exception('prekroceni limit na import poloziek');
         }
     }
     //oprav category rewrite link
     CategoryModel::repairCategoryRewriteLink();
 }
Beispiel #14
0
 public static function getAll($id_node)
 {
     return dibi::fetchAll("\n\t\t\tSELECT * \n\t\t\tFROM \n\t\t\t\tgallery \n\t\t\t\tLEFT JOIN gallery_image USING(id_node) \n\t\t\tWHERE \n\t\t\t\tgallery.id_node=%i", $id_node, "\t\t\t\t\n\t\t\tORDER BY sequence\n\t\t");
 }
Beispiel #15
0
	2      | Table
	3      | Computer
*/
// fetch a single row
echo "<h2>fetch()</h2>\n";
$row = dibi::fetch('SELECT title FROM products');
dump($row);
// Chair
// fetch a single value
echo "<h2>fetchSingle()</h2>\n";
$value = dibi::fetchSingle('SELECT title FROM products');
dump($value);
// Chair
// fetch complete result set
echo "<h2>fetchAll()</h2>\n";
$all = dibi::fetchAll('SELECT * FROM products');
dump($all);
// fetch complete result set like association array
echo "<h2>fetchAssoc('title')</h2>\n";
$res = dibi::query('SELECT * FROM products');
$assoc = $res->fetchAssoc('title');
// key
dump($assoc);
// fetch complete result set like pairs key => value
echo "<h2>fetchPairs('product_id', 'title')</h2>\n";
$pairs = $res->fetchPairs('product_id', 'title');
dump($pairs);
// fetch row by row
echo "<h2>using foreach</h2>\n";
foreach ($res as $n => $row) {
    dump($row);
Beispiel #16
0
 static function findBests()
 {
     return dibi::fetchAll("SELECT * FROM [article] WHERE [best]");
 }
<?php

require_once '../lib/dibi.min.php';
dibi::connect(array('driver' => 'mysqli', 'host' => 'localhost', 'username' => 'root', 'password' => '', 'database' => 'kiv_web'));
if (!empty($_POST)) {
    $idArticle = substr($_POST['idArticle'], 1, strlen($_POST['idArticle']) - 2);
    $idRecenzent = substr($_POST['idRecenzent'], 1, strlen($_POST['idRecenzent']) - 2);
    $exist = dibi::fetchAll("SELECT * FROM review WHERE id_article = %s AND id_reviewer = %i", $idArticle, $idRecenzent);
    $result = array();
    if (count($exist) != 0) {
        $result['msg'] = "Recenzent již příspěvek hodnotil!";
        $result['success'] = "false";
    } else {
        session_start();
        $arr = array('review.id_article' => $idArticle, 'review.id_reviewer' => $idRecenzent, 'review.is_reviewed' => 0, 'review.id_admin' => $_SESSION['login']['id']);
        dibi::query('INSERT INTO review', $arr);
        $result['success'] = "true";
    }
    echo json_encode($result);
} else {
    echo '{"success": "false"}';
}
Beispiel #18
0
 /**
  * 
  * @return DibiRow[]
  */
 public function return_all_articles_w_reviews()
 {
     return dibi::fetchAll("SELECT * FROM article " . "LEFT JOIN review ON id_article = article_id_article" . " LEFT JOIN user ON id_user = user_id_user");
 }
<?php

require_once '../lib/dibi.min.php';
dibi::connect(array('driver' => 'mysqli', 'host' => 'localhost', 'username' => 'root', 'password' => '', 'database' => 'kiv_web'));
if (!empty($_POST)) {
    $name = substr($_POST['login'], 1, strlen($_POST['login']) - 2);
    $pass = substr($_POST['password'], 1, strlen($_POST['password']) - 2);
    $existuje = dibi::fetchAll("SELECT * FROM users LEFT JOIN roles ON roles.id_role = users.id_role WHERE login = %s AND password = %s", $name, $pass);
    $result = array();
    if (count($existuje) != 0) {
        session_start();
        $_SESSION['login']['id'] = $existuje[0]['id_user'];
        $_SESSION['login']['login'] = $existuje[0]['login'];
        $_SESSION['login']['name'] = $existuje[0]['name'];
        $_SESSION['login']['role'] = $existuje[0]['description'];
        $result['success'] = "true";
        echo json_encode($result);
    } else {
        $result['success'] = "false";
        echo json_encode($result);
    }
}
Beispiel #20
0
<!DOCTYPE html><link rel="stylesheet" href="data/style.css">

<style> html { background: url(data/arrow.png) no-repeat bottom right; height: 100%; } </style>

<h1>Tracy | dibi</h1>

<p>Dibi can log queries and dump variables to the <a href="http://tracy.nette.org">Tracy</a>.</p>

<?php 
if (@(!(include __DIR__ . '/../vendor/autoload.php'))) {
    die('Install dependencies using `composer install --dev`');
}
// enable Tracy
Tracy\Debugger::enable();
$connection = dibi::connect(array('driver' => 'sqlite3', 'database' => 'data/sample.s3db', 'profiler' => array('run' => TRUE)));
// add panel to debug bar
$panel = new Dibi\Bridges\Tracy\Panel();
$panel->register($connection);
// query will be logged
dibi::query('SELECT 123');
// result set will be dumped
Tracy\Debugger::barDump(dibi::fetchAll('SELECT * FROM customers WHERE customer_id < ?', 38), '[customers]');
Beispiel #21
0
<h1>Nette\Debug & dibi example 2</h1>


<p>Dibi can dump variables via Nette\Debug, part of Nette Framework.</p>

<ul>
	<li>Nette Framework: http://nettephp.com
</ul>

<?php 
require_once 'Nette/Debug.php';
require_once '../dibi/dibi.php';
// enable Nette\Debug
Debug::enable();
dibi::connect(array('driver' => 'sqlite', 'database' => 'sample.sdb'));
// throws error
Debug::consoleDump(dibi::fetchAll('SELECT * FROM [customers] WHERE [customer_id] < %i', 38), '[customers]');
Beispiel #22
0
 function showUsers()
 {
     $user = NEnvironment::getUser();
     if (!$user->isAllowed('manage_user', 'edit')) {
         throw new LogicException('Nemáte dostatočné oprávnenie na túto sekciu');
     }
     try {
         //uprava uzivatela
         if (isset($_GET['id_auth_user']) and $_GET['id_auth_user'] != "") {
             $form = new NForm();
             $form->addText('name', 'Meno');
             $form->addText('surname', 'Priezvisko');
             $form->addText('email', 'Email');
             $form->addText('login', 'Login')->addRule(NFORM::FILLED, 'Login musí byť vyplnený');
             $form->addPassword('password', 'Heslo');
             $role = dibi::query('SELECT id_auth_role, key_name FROM auth_role ORDER BY key_name')->fetchPairs('id_auth_role', 'key_name');
             $form->addPassword('password2', 'Znova heslo')->addConditionOn($form['password'], NForm::FILLED)->addRule(NForm::FILLED, 'Zadejte heslo pro kontrolu')->addRule(NForm::EQUAL, 'Hesla se musi shodovat', $form['password']);
             $form->addSelect('id_auth_role', 'Uživateľská skupina:', $role);
             $form->addSubmit('addUser', 'Upravit');
             $form->onSubmit[] = array($this, 'changeUser');
             if (!$form->isSubmitted()) {
                 // 	první zobrazení, nastavíme výchozí hodnoty
                 $form->setDefaults(dibi::fetch("SELECT *, id_auth_role FROM auth_user LEFT JOIN [auth_user_role] USING(id_auth_user) WHERE auth_user.id_auth_user=%i", $_GET['id_auth_user']));
             }
             $form->fireEvents();
             MT::addTemplate(APP_DIR . '/require_modules/authentication/editUser.phtml', 'editUser');
             MT::addVar('editUser', 'form', (string) $form);
         }
     } catch (Exception $e) {
         ?>
   <div style="border:2px solid red;padding:5px;">
     <?php 
         echo $e->getMessage();
         ?>
   </div><?php 
     }
     if (!isset($_GET['id_auth_user'])) {
         if (isset($_GET['id_delete_user'])) {
             $this->deleteUser();
         }
         $form = new NForm();
         $form->getElementPrototype()->id = 'formAddUser';
         $form->addText('name', 'Meno');
         $form->addText('surname', 'Priezvisko');
         $form->addText('email', 'Email');
         $form->addText('login', 'Login')->addRule(NFORM::FILLED, 'Login musí byť vyplnený');
         $form->addPassword('password', 'Heslo')->addRule(NForm::FILLED, 'Zadejte heslo');
         $role = dibi::query('SELECT id_auth_role, key_name FROM [auth_role] ORDER BY key_name')->fetchPairs('id_auth_role', 'key_name');
         $form->addPassword('password2', 'Znova heslo')->addRule(NForm::FILLED, 'Zadejte heslo pro kontrolu')->addRule(NForm::EQUAL, 'Hesla se musi shodovat', $form['password']);
         $form->addSelect('id_auth_role', 'Uživateľská skupina:', $role);
         $form->addSubmit('addUser', 'Pridať použivateľa');
         $form->onSubmit[] = array($this, 'addUser');
         $form->fireEvents();
         MT::addTemplate(APP_DIR . '/require_modules/authentication/showUsers.phtml', 'showUsers');
         $list = dibi::fetchAll("\n      \tSELECT \n      \t\t*\n      \tFROM \n      \t\tauth_user\n      \tORDER BY login");
         MT::addVar('showUsers', 'list', $list);
         MT::addVar('showUsers', 'form', $form);
     }
 }
Beispiel #23
0
 public function checkTables()
 {
     $traversal = dibi::fetchAll("SELECT `id` FROM `{$this->prefix}traversal{$this->suffix}` ORDER BY `left`");
     $order = dibi::fetchAll("SELECT `id` FROM `{$this->prefix}order{$this->suffix}` ORDER BY `order`");
     $levelOrderBy = 'ORDER BY ';
     for ($i = 1; $i <= $this->maxDepth; $i++) {
         $levelOrderBy .= "`L{$i}`, ";
     }
     $levelOrderBy .= "`L{$i}`";
     $level = dibi::fetchAll("SELECT `id` FROM `{$this->prefix}level{$this->suffix}` {$levelOrderBy}");
     foreach ($traversal as $key => $node) {
         if ($node['id'] != $order[$key]['id']) {
             echo "Traversal's and order's nodes aren't in same order!";
             break;
         }
     }
     foreach ($traversal as $key => $node) {
         if ($node['id'] != $level[$key]['id']) {
             echo "Traversal's and level's nodes aren't in same order!";
             break;
         }
     }
     foreach ($order as $key => $node) {
         if ($node['id'] != $level[$key]['id']) {
             echo "Order's and level's nodes aren't in same order!";
             break;
         }
     }
 }
<?php

require_once '../lib/dibi.min.php';
dibi::connect(array('driver' => 'mysqli', 'host' => 'localhost', 'username' => 'root', 'password' => '', 'database' => 'kiv_web'));
if (!empty($_POST)) {
    $name = substr($_POST['fullname'], 1, strlen($_POST['fullname']) - 2);
    $email = substr($_POST['email'], 1, strlen($_POST['email']) - 2);
    $org = substr($_POST['org'], 1, strlen($_POST['org']) - 2);
    $login = substr($_POST['login'], 1, strlen($_POST['login']) - 2);
    $pass = substr($_POST['password'], 1, strlen($_POST['password']) - 2);
    $users = dibi::fetchAll("SELECT * FROM users WHERE email = %s OR login = %s", $email, $login);
    $result = array();
    if (count($users) != 0) {
        foreach ($users as $item) {
            if ($item['email'] == $email) {
                $result['msg'] = "Email je již registrován!";
                break;
            } else {
                if ($item['login'] == $login) {
                    $result['msg'] = "Login je již obsazen!";
                    break;
                }
            }
        }
        $result['success'] = "false";
    } else {
        $arr = array('users.name' => $name, 'users.email' => $email, 'users.login' => $login, 'users.password' => $pass, 'users.organisation' => $org);
        dibi::query('INSERT INTO users', $arr);
        $result['success'] = "true";
    }
    echo json_encode($result);
Beispiel #25
0
    function showForm()
    {
        $session = NEnvironment::getSession('Authentication');
        if ($session["superadmin"] != 1) {
            header("Location: admin.php");
            exit;
        }
        try {
            if (isset($_POST['addModul'])) {
                $this->addModul();
            }
            if (isset($_POST['load_modul'])) {
                $this->loadModulFile();
            }
            if (isset($_GET['id_type_modul'])) {
                $this->deleteModul();
            }
        } catch (Exception $e) {
            ?>
        <div style="border:2px solid red;padding:5px;">
          <?php 
            echo $e->getMessage();
            ?>
        </div><?php 
        }
        ?>
  <form method="post" enctype="multipart/form-data" action="">
    <label>Nahratie nového modulu (.zip)</label> <input type="file" name="modul_file_zip" />
    <input type="submit" name="load_modul" value="Nahrať" />
  </form>
   <form id="formAddModul" action="" method="post" style="padding:5px 0px;">
      <label>Meno modulu</label>
      <input type="text" name="name" value="" />      
       Modul: <select name="dir">
        <?php 
        $dir = "moduls/";
        echo filetype($dir);
        if (is_dir($dir)) {
            if ($dh = opendir($dir)) {
                while (($file = readdir($dh)) !== false) {
                    if ($file != "." and $file != "..") {
                        ?>
 <option value="<?php 
                        echo $file;
                        ?>
"><?php 
                        echo $file;
                        ?>
</option><?php 
                    }
                }
                closedir($dh);
            }
        }
        ?>
       
      </select>
      Zobraziť <select style="width:50px;" name="visible_for_user"><option value="1">áno</option><option value="0">nie</option></select>
      <input type="submit" class="sub" name="addModul" value="Pridat" />
    </form>

    <form action="" method="post">      
      <table id="highlight">
      <thead><tr><th></th><th>Názov</th><th>Modul</th><th>Zobraziť</th><th>Zmazať</th></tr></thead>
      <tbody>
      <?php 
        $list = dibi::fetchAll("SELECT * FROM type_modul ORDER BY name");
        foreach ($list as $l) {
            ?>
<tr>
        <td><img src="/moduls/<?php 
            echo $l['dir'];
            ?>
/icon.gif" alt="<?php 
            echo $l['name'];
            ?>
" /></td><td><?php 
            echo $l['name'];
            ?>
</td><td><?php 
            echo $l['dir'];
            ?>
</td><td><?php 
            echo $l['visible_for_user'];
            ?>
</td><td><a href="javascript:confl('Naozaj chcete odstrániť <?php 
            echo $l['name'];
            ?>
','?section=admin_modules&amp;id_type_modul=<?php 
            echo $l['id_type_modul'];
            ?>
');"><img src="<?php 
            echo RELATIVE_PATH;
            ?>
templates/global_img/delete.gif" alt="Zmazat" /></a></td>
        </tr><?php 
        }
        ?>
      </tbody>
      </table>
      <script type="text/javascript">	
          	var th = new tableHighlighter( 'highlight' );	
      </script>
    </form>    
    <?php 
    }
Beispiel #26
0
 public function run()
 {
     if (false == file_exists($this->_baseDir . '/graphs')) {
         mkdir($this->_baseDir . '/graphs');
     }
     $dotfiles = array();
     $query = '
         SELECT
             t.id as classId,
             t.name as className,
             m.id as magentoId,
             IF(LOCATE("extends", definition), TRIM(REPLACE(SUBSTR(definition, LOCATE("extends", definition)+8), "{", "")), NULL) as parentClassName,
             s.definition,
             CONCAT_WS("-", m.edition, m.version) as mage
         FROM [classes] t
             JOIN [class_signature] ts ON ( t.id = ts.class_id )
             JOIN [signatures] s ON ( ts.signature_id = s.id)
             JOIN [magento_signature] ms ON ( s.id = ms.signature_id)
             JOIN [magento] m ON ( m.id = ms.magento_id)
         ';
     $classInheritance = dibi::fetchAll($query);
     foreach ($classInheritance as $inheritance) {
         $childName = $inheritance->className;
         $parentName = $inheritance->parentClassName;
         $mage = $inheritance->mage;
         if (false === array_key_exists($inheritance->magentoId, $this->_magento)) {
             $this->_classes[$inheritance->magentoId] = $mage;
         }
         if (false === array_key_exists($mage, $this->_classes)) {
             $this->_classes[$mage] = array();
         }
         if (false === array_key_exists($mage, $this->_parents)) {
             $this->_parents[$mage] = array();
         }
         if (false === array_key_exists($childName, $this->_classes)) {
             $this->_classes[$mage][$childName] = new Klass($childName);
         }
         $this->_classes[$mage][$childName]->setId($inheritance->classId);
         $this->_classes[$mage][$childName]->setMagentoId($inheritance->magentoId);
         $this->_classes[$mage][$childName]->setDefinition($inheritance->definition);
         /* remove child from main parent array, if a class inherits from another one */
         if (array_key_exists($childName, $this->_parents)) {
             unset($this->_parents[$childName]);
         }
         $parentName = trim(preg_replace('/implements.*$/s', '', $parentName));
         $parentName = trim(preg_replace('/[^A-Za-z0-9_]/', '', $parentName));
         if (0 < strlen($parentName)) {
             $dotfile = $this->_baseDir . '/graphs/inheritance_' . $inheritance->mage . '.dot';
             if (false == file_exists($dotfile)) {
                 file_put_contents($dotfile, 'digraph G {' . PHP_EOL);
                 $dotfiles[] = $dotfile;
             }
             if (false === array_key_exists($parentName, $this->_classes[$mage])) {
                 $this->_classes[$mage][$parentName] = new Klass($parentName);
                 $this->_classes[$mage][$parentName]->setDefinition($inheritance->parentClassName);
                 $this->_parents[$mage][$parentName] = $this->_classes[$mage][$parentName];
             }
             file_put_contents($dotfile, $parentName . ' -> ' . $childName . ';' . PHP_EOL, FILE_APPEND);
             $parentClass = $this->_classes[$mage][$parentName];
             $childClass = $this->_classes[$mage][$childName];
             $parentClass->addChild($childClass);
         }
     }
     foreach ($dotfiles as $dotfile) {
         file_put_contents($dotfile, '}', FILE_APPEND);
     }
     foreach ($this->_parents as $mage => $parents) {
         foreach ($parents as $parent) {
             $this->_saveInheritedMethods($parent);
         }
     }
 }
<!DOCTYPE html><link rel="stylesheet" href="data/style.css">

<h1>Nette\Debug & Variables | dibi</h1>

<p>Dibi can dump variables via Nette\Debug, part of Nette Framework.</p>

<ul>
	<li>Nette Framework: http://nette.org
</ul>

<?php 
require_once 'Nette/Debug.php';
require_once '../dibi/dibi.php';
// enable NDebug
NDebug::enable();
dibi::connect(array('driver' => 'sqlite', 'database' => 'data/sample.sdb', 'profiler' => array('run' => TRUE)));
NDebug::barDump(dibi::fetchAll('SELECT * FROM customers WHERE customer_id < %i', 38), '[customers]');
Beispiel #28
0
dibi::connect($db_config);
$prfr = dibi::fetchAll("SELECT * FROM prfr ORDER BY datetime DESC LIMIT 1000");
$prfr = array_reverse($prfr);
//print_r($prfr);
echo '<table cellspacing=0 cellpadding=0 style="background:url(http://static.sashe.cz/images/gbg.gif);height:300px;"><tr>';
foreach ($prfr as $sample) {
    echo '<td>';
    echo '<img src="http://static.sashe.cz/images/black_50.png" width=1 height="' . round($sample['ms'] / 50) . '" title="' . $sample['datetime'] . ' ' . $sample['ms'] . 'ms">';
    echo '<br>';
    echo '<img src="http://static.sashe.cz/images/black_88.png" width=1 height="' . round(($sample['mstotal'] - $sample['ms']) / 50) . '" >';
    echo '</td>';
}
echo '</tr></table>';
define("DIVIDER", 25);
unset($prfr);
$prfr1 = dibi::fetchAll("SELECT * FROM prfr ORDER BY datetime DESC LIMIT 40000");
$prfr1 = array_reverse($prfr1);
echo '<table cellspacing=0 cellpadding=0 style="background:url(http://static.sashe.cz/images/gbg.gif);height:300px;"><tr>';
foreach ($prfr1 as $key => $sample) {
    $mstotal = $mstotal + $sample['ms'];
    $w++;
    if ($w == DIVIDER) {
        $prfr[$w2]['mstotal'] = $mstotal;
        $prfr[$w2]['datetime'] = $sample['datetime'];
        $w = $ms = $mstotal = 0;
        $w2++;
    }
}
foreach ($prfr as $sample) {
    if ($sample['mstotal'] / DIVIDER > 3000) {
        $sample['mstotal'] = 3000;
Beispiel #29
0
 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);
     }
 }
Beispiel #30
0
 public static function commentList()
 {
     $list = dibi::fetchAll("\n\t\tSELECT \n\t\t\tcomment.*, \n\t\t\tmenu_item.url_identifier AS menu_url_identifier,\n\t\t\tarticle.url_identifier,\n\t\t\tDATE_FORMAT(comment.adddate, '%d.%m.%Y %H:%i:%s') AS adddate_formated,\n\t\t\tarticle.title AS article_title \n\t\tFROM \n\t\t\t[comment] \n\t\t\tJOIN article USING(id_node)\n\t\t\tLEFT JOIN [node] USING(id_node)\n\t\t\tLEFT JOIN [menu_item] USING(id_menu_item) \n\t\tWHERE \n\t\t\tcomment.status=0\n\t\tORDER BY comment.adddate\n\t\t");
     MT::addTemplate(dirname(__FILE__) . '/admin_commentList.phtml', 'comment');
     MT::addVar('comment', 'list', $list);
 }