Jump to content

bogdaniel

Members
  • Posts

    65
  • Joined

  • Last visited

Posts posted by bogdaniel

  1. Here's how, but you will have to do the TWIG bits

    <?php
    include("db_inc.php");  // defines credentials
    $db = new mysqli(HOST,USERNAME,PASSWORD,'bogdaniel');
    
    // GET THE ROLES TO USE AS HEADINGS
    
    $sql = "SELECT RoleId, RoleName
            FROM tbl_user_roles
            ORDER BY RoleId";
    $res = $db->query($sql);
    $roles = array();
    while (list($rid, $rnm) = $res->fetch_row()) {
        $roles[$rid] = $rnm;
    }
    
    $theads = "<tr><th>Permission</th><th>".join('</th><th>',$roles)."</th></tr>\n";
    $tdata = '';
    
    // CREATE A DEFAULT ARRAY TO STORE THE ROLE VALUES FOR EACH PERMISSION
    // THIS WILL BE UPDATED AND OUTPUT WHEN THE PERMISSION CHANGES
    
    $default = array_fill_keys(array_keys($roles), 'x');
    
    // NOW WE CAN GET THE DATA FOR THE TABLE
    
    $sql = "SELECT t3.PermissionName, t2.RoleId 
            FROM tbl_user_role_perm AS t1
                INNER JOIN tbl_user_roles AS t2 ON t1.RoleId = t2.RoleId
                INNER JOIN tbl_user_permissions AS t3 ON t1.PermissionId = t3.PermissionId
            ORDER BY t1.PermissionId, t2.RoleId";
    $res = $db->query($sql);
    $permArray = $default;
    $currPerm = '';
    while (list($perm, $rid) = $res->fetch_row()) {
        if ($perm != $currPerm) {      // change of permission?
            if ($currPerm != '') {
                $tdata .= "<tr><td class='perm'>$currPerm</td><td>"
                    . join ('</td><td>', $permArray) . "</td></tr>\n";
            }
            $currPerm = $perm;         // reset for next permission
            $permArray = $default;
        }
        $permArray[$rid] = '&check;';  // update if perm/role exists
    }
    // DO NOT FORGET THE FINAL PERMISSION
    $tdata .= "<tr><td class='perm'>$currPerm</td><td>"
        . join ('</td><td>', $permArray) . "</td></tr>\n";
    ?>
    <html>
    <head>
        <title>Sample</title>
        <meta name="author" content="Barand">
        <meta name="creation-date" content="10/31/2014">
        <style type="text/css">
            table {
                border-collapse: collapse;
            }
            th {
                width: 70px;
                background-color: #ccc;
                font-family: sans-serif;
                font-size: 8pt;
            }
            td {
                font-family: sans-serif;
                font-size: 12pt;
                text-align: center;
            }
            td.perm {
                font-size: 8pt;
                text-align: left;
                width: 150px;
            }
        </style>
    </head>
    <body>
        <table border='1'>
            <?=$theads?>
            <?=$tdata?>
        </table>
    </body>
    </html>
    

    Gives:

    when i get  home i'll test the code no worries for the twig i'll rewrite the code to be with what i'm using i already noticed a difference in the mysql query that from what i can think of might make the difference, i wasn't sure on the sql part if it's done right and complete.. i'm sure i've missed out something about the data output. let know in 3 hours what i've done. cheers for answering to my post

  2. yes it retrieves the data but i didn't manage echoing in the table. if you check the html output you would see there that it created a third Catalog-View for moderator instead of putting 1 on the column moderator.

    for the number 2

        public function ListPermissionNames() {
            $this->database->query("SELECT t2.RoleName, t2.RoleName, t3.PermissionName, t3.PermissionName, t1.PermissionId FROM tbl_user_role_perm AS t1
    INNER JOIN tbl_user_roles AS t2 ON t1.RoleId = t2.RoleId
    INNER JOIN tbl_user_permissions AS t3 ON t1.PermissionId = t3.PermissionId");
            $this->database->execute();
            $this->database->setFetchMode(PDO::FETCH_ASSOC);
            return $this->database->resultSet(PDO::FETCH_GROUP, PDO::FETCH_ASSOC);

    3 & 4 i posted a picture with this post to show exact the example that i wanna achieve and i don't know how to do it. i'm generating td's and everything but instead of putting 1 for administrator and 1 for moderator it creates a new line bellow ( see HTML OUTPUT).

  3. Hello I have an array with data from `mysql` that I would like to output it in a table using twig.

    The image is an example of want i want to achieve but without any luck.

    table.png

    `print_r` of the array data
     

            Array
        (
            [Administrator] => Array
                (
                    [0] => Array
                        (
                            [RoleName] => Administrator
                            [PermissionName] => Catalog-View
                            [PermissionId] => 1
                        )
        
                    [1] => Array
                        (
                            [RoleName] => Administrator
                            [PermissionName] => Catalog-Edit
                            [PermissionId] => 2
                        )
        
                    [2] => Array
                        (
                            [RoleName] => Administrator
                            [PermissionName] => Catalog-Delete
                            [PermissionId] => 3
                        )
        
                )
        
            [Moderator] => Array
                (
                    [0] => Array
                        (
                            [RoleName] => Moderator
                            [PermissionName] => Catalog-View
                            [PermissionId] => 1
                        )
        
                )
        
        )



    The `HTML` code:
     

        <table>
            <tr>
                <thead>
                    <th>Controller - Action</th>
                    {% for permission in permissions %}
                    {% for item in permission %}
                    <th>{{item.RoleName}}</th>
                    {% endfor %}
                    {% endfor %}
                </thead>
            </tr>
            {% for permission in permissions %}
            {% for item in permission %}
            <tr>
                <td>{{item.PermissionName}}</td>
                <td>{{item.PermissionId}}</td>
            </tr>
            {% endfor %}
            {% endfor %}
        </table>



    OUTPUT:

        <table>
            <tbody>
                <tr></tr>
            </tbody>
            <thead>
                <tr>
                    <th>Controller - Action</th>
                    <th>Administrator</th>
                    <th>Administrator</th>
                    <th>Administrator</th>
                    <th>Moderator</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>Catalog-View</td>
                    <td>1</td>
                </tr>
                <tr>
                    <td>Catalog-Edit</td>
                    <td>2</td>
                </tr>
                <tr>
                    <td>Catalog-Delete</td>
                    <td>3</td>
                </tr>
                <tr>
                    <td>Catalog-View</td>
                    <td>1</td>
                </tr>
            </tbody>
        </table>


    Later Edit
    MySQL Query:
     

        SELECT t3.PermissionName, t1.PermissionId, t2.RoleName FROM tbl_user_role_perm AS t1
        INNER JOIN tbl_user_roles AS t2 ON t1.RoleId = t2.RoleId
        INNER JOIN tbl_user_permissions AS t3 ON t1.PermissionId = t3.PermissionId


    MySQL Dump:
     

        -- Dumping structure for table tbl_user_permissions
        CREATE TABLE IF NOT EXISTS `tbl_user_permissions` (
          `PermissionId` int(11) NOT NULL AUTO_INCREMENT,
          `PermissionName` varchar(50) NOT NULL,
          `PermissionDescription` varchar(100) NOT NULL,
          PRIMARY KEY (`PermissionId`)
        ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
        
        -- Dumping data for table tbl_user_permissions: ~2 rows (approximately)
        DELETE FROM `tbl_user_permissions`;
        /*!40000 ALTER TABLE `tbl_user_permissions` DISABLE KEYS */;
        INSERT INTO `tbl_user_permissions` (`PermissionId`, `PermissionName`, `PermissionDescription`) VALUES
            (1, 'Catalog->View', 'View Catalog Method'),
            (2, 'Catalog->Edit', 'Edit Catalog Method'),
            (3, 'Catalog->Delete', 'Delete Catalog Method');
        /*!40000 ALTER TABLE `tbl_user_permissions` ENABLE KEYS */;
        
        
        -- Dumping structure for table tbl_user_role
        CREATE TABLE IF NOT EXISTS `tbl_user_role` (
          `UserRoleId` int(10) NOT NULL AUTO_INCREMENT,
          `UserId` int(10) NOT NULL,
          `RoleId` int(10) unsigned NOT NULL,
          PRIMARY KEY (`UserRoleId`),
          KEY `FK_tbl_user_role_tbl_user_roles` (`RoleId`),
          KEY `UserId` (`UserId`)
        ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
        
        -- Dumping data for table tbl_user_role: ~2 rows (approximately)
        DELETE FROM `tbl_user_role`;
        /*!40000 ALTER TABLE `tbl_user_role` DISABLE KEYS */;
        INSERT INTO `tbl_user_role` (`UserRoleId`, `UserId`, `RoleId`) VALUES
            (1, 13, 22),
            (2, 14, 22);
        /*!40000 ALTER TABLE `tbl_user_role` ENABLE KEYS */;
        
        
        -- Dumping structure for table tbl_user_roles
        CREATE TABLE IF NOT EXISTS `tbl_user_roles` (
          `RoleId` int(10) unsigned NOT NULL AUTO_INCREMENT,
          `RoleName` varchar(50) NOT NULL,
          `CreatedDate` datetime NOT NULL,
          `ModifiedDate` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
          PRIMARY KEY (`RoleId`)
        ) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8;
        
        -- Dumping data for table tbl_user_roles: ~7 rows (approximately)
        DELETE FROM `tbl_user_roles`;
        /*!40000 ALTER TABLE `tbl_user_roles` DISABLE KEYS */;
        INSERT INTO `tbl_user_roles` (`RoleId`, `RoleName`, `CreatedDate`, `ModifiedDate`) VALUES
            (22, 'Administrator', '2014-10-28 09:53:08', NULL),
            (23, 'Moderator', '2014-10-28 09:53:13', NULL),
            (24, 'Admin', '2014-10-28 12:22:05', '2014-10-28 12:22:06'),
            (25, 'User', '2014-10-29 15:10:36', '2014-10-29 15:10:37'),
            (26, 'SuperUser', '2014-10-29 15:10:45', '2014-10-29 15:10:46'),
            (27, 'Accountant', '2014-10-29 15:10:53', '2014-10-29 15:10:54'),
            (28, 'God', '2014-10-29 15:11:02', '2014-10-29 15:11:02');
        /*!40000 ALTER TABLE `tbl_user_roles` ENABLE KEYS */;
        
        
        -- Dumping structure for table tbl_user_role_perm
        CREATE TABLE IF NOT EXISTS `tbl_user_role_perm` (
          `RoleId` int(10) unsigned NOT NULL,
          `PermissionId` int(10) unsigned NOT NULL,
          KEY `RoleId` (`RoleId`),
          KEY `PermissionId` (`PermissionId`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
        
        -- Dumping data for table tbl_user_role_perm: ~3 rows (approximately)
        DELETE FROM `tbl_user_role_perm`;
        /*!40000 ALTER TABLE `tbl_user_role_perm` DISABLE KEYS */;
        INSERT INTO `tbl_user_role_perm` (`RoleId`, `PermissionId`) VALUES
            (22, 2),
            (22, 1),
            (23, 1),
            (22, 3);
        /*!40000 ALTER TABLE `tbl_user_role_perm` ENABLE KEYS */;
        /*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
        /*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */;
        /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
    

    Can  you help me to make the coding required so that the correct column have the correct permissions? thank you in advance.

  4. 3. Any improvements to the code?

     

    Pull the entire menu in one query, using LEFT JOINs.

     

    It will improve performance significantly.

     

    Also, consider revising the schema so "links" and "categories" are both stored in the same table of "menu_elements" - a self-referencing table with a "type" column defining what type of menu item it is.

    i'll do that :-)

    what about the view part any sugestions.. ? :)

  5. recently i started working with TinyMVC, wrote a simple menu model and i have few questions for those who are using it .. or used before.

    1. For the following code should i keep it as Model or as a Plugin?

    2. How should i implement it in the view and use it on every page that is required without breaking the ideea of mvc and without rewriting again and again for each controller?

    3. Any improvements to the code?

    4. Need the mysql tables ?

     

    <?php
    class Menu_Model extends TinyMVC_Model
    {
    
        public function __construct()
        {
            parent::__construct();
        }
    
        public function listMenu()
        {
            return $this->db->query_all("SELECT * FROM menu_links WHERE is_deleted = 0 ORDER BY position");
        }
    
        public function listCategorys($menuLinkId)
        {
            return $this->db->query_all("SELECT * FROM menu_subcategorys WHERE menuLinkId = ? AND is_deleted = 0 ORDER BY position", array($menuLinkId));
        }
    
        public function buildMenu()
        {
            $this->listMenu = $this->listMenu();
            foreach($this->listMenu as $this->listMenuKey => $this->listMenuValue)
            {
                $this->listCategorys = $this->listCategorys($this->listMenuValue['menuLinkId']);
                if(!empty($this->listCategorys))
                    $this->listMenu[$this->listMenuKey]['child'] = $this->listCategorys;
            }
    
            return $this->listMenu;
        }
    }

  6. hello guys.. i have a strange question... when you work on a website that has a huge menu(per country for example like a travel agency website) and needs to have the option to add delete items from the menu and submenu how do you store it ? xml .. mysql? any sugestions tips..hints..?

     

     

    Thank you very much for you help.

  7. Hi,

     

    I have a site that is alcohol related and by law i must have a page where visitors verify if they are of age.

     

    I have a very simple code snippet at the top of each page that checks if the visitor is verified.

    <?php
    
    //Start the session
    session_start();
    
    /*
    * If they haven't passed the age test
    * then the age_verified session will not
    * be set, since it is only set if they
    * say they are 21 years of age.
    */
    if(!isset($_SESSION['age_verified'])) {
        header("Location: verify.php");
        exit;
    }
    
    ?>
    

     

    Is is possible to allow search engines such as Google, Yahoo, Bing, etc. to access these pages and index them? Maybe by verifying the user agent or something?

     

    i`m not sure if you talk only stupid things but this you could achieve creating an array with the user agent of the bots(i think you can find on google about them) but for someone smart and with firefox could enter on your website by changing the user agent.

     

     

    click check this out for more information's.

  8. hello i`m having a small question actually a problem for me because i`m not sure on what..should i use.

    when you build a user system and after you check the credentials for the user you create a session ok. but what should i use session_register or $_SESSION?

  9. Hello i've just started to build a website for my boss that will have an online shop a photo gallery a presentation of the company(it's a small one i don't know what he wants to write) a contact form, projects that have been done by them. and this means it will require a lot of php and mysql in it.

    on the design part i was thinking on going on flash animations but because of the php and other things that will need to be implemented.. i'm not sure what to do the website is about decorating interior designs.

     

    My question is should i go for a static design or for a flash implementation and if i got for flash should be entire website or do some hard coded stuff and make a part of it flash and other parts be pure php css.... i need an advice.. maybe ideas about the design the guy showed me that he would want something like:

     

    http://www.innova.ro

    http://www.roma.ro/

    http://www.kartell.it/

  10. i apologize what i wanted to ask was:

    In game development the resource system you know wood stone stuff like that you get let's say 3200 wood per hour or 6200 if you are a higher lvl on the wood cutter. How should i make this update? when the user logins? page refresh... this is what i wanted to know :D i've read on a website that most of the games use cron jobs to update the resources gained per hour ..

  11. hello i was doing a little google research until i found a website with a tutorial about creating urls without using mod rewrite can someone please explain it to me and give me some example as procedual code and oop? thank you very much for helping me in your spare time.

     

     

    <?php

     

    // Get the URL relative to the script

    $url = $_SERVER['PATH_INFO'];

     

    // If for some reason $_SERVER["PATH_INFO"] does not work then

    // you could use $_SERVER["REQUEST_URI"] or $_SERVER["PHP_SELF"]

     

    // Remove the /index.php/ at the beginning

    $url = preg_replace('/^(\/)/','',$url);

     

    // Split URL into array

    $url = explode('/',$url);

     

    // Display array

    print_r($url);

     

    ?>

    [/[code=php:0]

  12. Hello .. i'm trying to understand the url routing in mvc pattern but for the moment i couldn`t understand to much i know that it's base is in a var like $_GET['url'](used as an example) but i couldn`t understand how to pass the a link like index?url=details&category=1&id=4(as an example) can please someone help with some explanations codes.. articles.. from what i found on google looking for php url routing//routes//tutorials//articles i didn`t find anything that would help me. :(

     

    thank you for your support and help.

  13. I was playing with sqlite and did come up with a simple table structure, and a query that appears to work.

     

    I built my tables like

    CREATE TABLE [ticketnumbers] (
    [id] INTEGER  PRIMARY KEY AUTOINCREMENT NOT NULL,
    [tid] INTEGER  NOT NULL,
    [number] TINYINT  NOT NULL
    );
    
    CREATE TABLE [tickets] (
    [id] INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT,
    [uid] INTEGER  NOT NULL,
    [purchased] TIMESTAMP DEFAULT CURRENT_TIMESTAMP NULL
    );
    
    CREATE TABLE [users] (
    [id] INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT,
    [name] VARCHAR(30)  UNIQUE NOT NULL,
    [password] VARCHAR(16)  NOT NULL,
    [email] VARCHAR(64)  UNIQUE NOT NULL,
    [added] TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
    [laston] TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
    );

     

    well I got a little out of hand on users table, but just needed some visuals.

    than I created some test data, 100 users, 200 tickets purchases, and 1600 numbers

    (this was pure random data, so didnt make every ticket hold 12 numbers)

     

    a quick check with SQL, to verify tickets and numbers

    SELECT * FROM ticketnumbers WHERE number IN(12,31,68) order BY tid

     

    but ya see how complex it gets?

    so I made another query that kinda gave me more useful info

    SELECT tid,count(number) as matches,group_concat(number) as numbers FROM ticketnumbers WHERE number IN(12,31,68) GROUP BY tid ORDER BY matches DESC

     

    Hmmm, not bad :)

    the query seemed to work, but this was all done with just the db, random generated test date

    and a lil searching on the net (I learned that group_concat isnt supported in SQLite until version 3.5.4))

     

     

    thank you very much for you example and for all those who posted here.. you've been really helping i've solved the problems and already started to coding.. diagram for mysql is finish and the diagram for the website backend + user :)

    i will hit topic solved but if anyone is interested to continue this topic.. :) and come with ideeas i think everyone will be glad to hear them.

  14. So am i correct in saying you want, the user to enter 20 number(range 1-80),

    and then th server, to generates 2 random number (also range 1-80) and then check to see if its 2 are in the list of 20 the user submitted ?

     

    one question.. where does the mysql come into play ?

     

     

    So am i correct in saying you want, the user to enter 20 number(range 1-80),

    and then th server, to generates 2 random number (also range 1-80) and then check to see if its 2 are in the list of 20 the user submitted ?

     

    one question.. where does the mysql come into play ?

     

     

    mm it's not only for one user it's for more.. let's say about 100 - 200 users submit this 20 numbers.. and computer generates 12 numbers .. and that has to check if one or more of those 12 numbers are identic with one or more numbers submited by a users

     

     

     

     

     

    Do you know about if statements?

     

    yes i know about if statements..

  15. Hello i'm trying to build a script that would do something like this:

    the user is allowed to submit 20 numbers

    ex: 3,7,20,25,64....

    after all users submited their numbers

    computer will generate using rand() 12 numbers from 1 to 80(same as the user has the option to choose from 1 to 80).

    after this two points i must check if one or more of the computers generated numbers is = to 1 or more numbers submited by a user.

    i'm not asking for you to provide a code or something like this...

    my question is how can i do this using php and mysql... examples are welcome.. :)

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.