We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32365
    • 42 Posts
    Hmm something strange is going on. When I call the value of the table column "user" from the database, this is what I’m receiving "Resource id #13" when in the database the name of the account I created is clearly listed "zooba".

    This is the snippet of code I’m using,

    <?php
    .....
    $user = $_SESSION[’webShortname’];
    ....
    INSERT INTO modx_site_content (..., ’$user’ )
    ...

    As I said above, this puts the text "zooba" into the database. Then when it’s called using this code,

    ...
    $pageid = $modx->documentIdentifier; (the user name is saved in the same row as the document id of the page)
    $user = mysql_query("SELECT user FROM modx_site_content WHERE id=’$pageid’") or die(mysql_error());
    echo $user; (I echo’d it as a test to see the result)
    ...

    the result is "Resource id #13". I’m not sure where it’s getting that resource id from the text "zooba".

    Anyone have an idea what’s happening?
      • 5340
      • 1,624 Posts
      I’m not sure what you are trying to do but adding a column to modx_site_content tables is not a good thing to do.

      Why aren’t you using TVs(template variables) to store additional information. Have a look at the modx_site_tmplvars and modx_site_tmplvar_contentvalues.

      use something like
      $vf = array();
      $vf['tmplvarid'] = 3;
      $vf['contentid'] = $newId;
      $vf['value'] = 'your value';
      $modx->db->insert( $vf, $modx->getFullTableName('site_tmplvar_contentvalues') );


      to store you TV values

      If you still want to add information your way create a new table called modx_site_content_extended. The table will have to fields: id and user


      I hope this helps
        • 4172
        • 5,888 Posts
        as I said above, you can do this with FDM.
        You can have different webgroups with these permissions:

        moderator-webgroup:
        add new pages, edit all pages, delete pages

        editor-webgroup:
        can add new pages (if allowed), can edit only own pages.
        I’ve used it several times and it workes well, once configured for your needs.

        and more..........

        if you want to create your own system have a look to FDMs code, to get an idea, how you can handle these permissions.





          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 32365
          • 42 Posts
          Quote from: cipa at Nov 16, 2009, 10:57 PM

          I’m not sure what you are trying to do but adding a column to modx_site_content tables is not a good thing to do.

          Why aren’t you using TVs(template variables) to store additional information. Have a look at the modx_site_tmplvars and modx_site_tmplvar_contentvalues.

          use something like
          $vf = array();
          $vf['tmplvarid'] = 3;
          $vf['contentid'] = $newId;
          $vf['value'] = 'your value';
          $modx->db->insert( $vf, $modx->getFullTableName('site_tmplvar_contentvalues') );


          to store you TV values

          If you still want to add information your way create a new table called modx_site_content_extended. The table will have to fields: id and user


          I hope this helps
          I haven’t noticed any problems from having an extra column, existing pages and newly created ones don’t have any bugs in them since the column is left blank when not created specifically from my form.

          I already have several template variables that add the content onto the page. Those are working fine(although I have mine written out differently since the content for them is called from a form) and I’m not having any problems with them.

          Right the only problem I have is calling a user’s webShortname back from the database where it is saved as the actual username and not as a resource id#.

          as I said above, you can do this with FDM.
          You can have different webgroups with these permissions:

          moderator-webgroup:
          add new pages, edit all pages, delete pages

          editor-webgroup:
          can add new pages (if allowed), can edit only own pages.
          I’ve used it several times and it workes well, once configured for your needs.

          and more..........

          if you want to create your own system have a look to FDMs code, to get an idea, how you can handle these permissions.

          My goal is have a function where a user submits information to a form and, when logged in, only that user can edit it’s content. That FDM would allow anyone in the usergroup to edit it as well.

          I’ll have to download and read through the code to see if it any any single user identification features though. At the very least it’ll help me to learn modx/php more(as you have probably guessed I’m new to both).
            • 4172
            • 5,888 Posts
            <?php
            
            $docid=$modx->documentObject['id'];
            $rs=$modx->db->select('user',$modx->getFullTablename('site_content'),'id='.$docid);
            $doc=$modx->db->getRow($rs);
            $user=$doc['user'];
            echo $user;
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              FDM already does this. The site_content table has a createdby field, which is the ID of the user that created it. This is checked against the SESSION[’webInternalKey’] value (since in this case the document was created by a web user and not a manager user), which will be the logged-in user’s ID.

              http://www.sottwell.com/article-sessions.html

              If you’re having a problem with resources being returned (which all queries do), and don’t know exactly what is being returned, try this:

              echo "<pre>";
              print_r($user);
              echo "</pre>";
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 32365
                • 42 Posts
                Quote from: Bruno17 at Nov 17, 2009, 02:31 AM

                <?php
                
                $docid=$modx->documentObject['id'];
                $rs=$modx->db->select('user',$modx->getFullTablename('site_content'),'id='.$docid);
                $doc=$modx->db->getRow($rs);
                $user=$doc['user'];
                echo $user;

                Nice I’m going to try that code. Thank you for the assistance.

                FDM already does this. The site_content table has a createdby field, which is the ID of the user that created it. This is checked against the SESSION[’webInternalKey’] value (since in this case the document was created by a web user and not a manager user), which will be the logged-in user’s ID.

                http://www.sottwell.com/article-sessions.html

                If you’re having a problem with resources being returned (which all queries do), and don’t know exactly what is being returned, try this:

                I didn’t realize it had that capability. All the summaries of FDM I read only mentioned giving that option to entire user/webgroups.
                  • 32365
                  • 42 Posts
                  Alright I got it working grin . I’m pleased I managed to actually do it(it was good php learning/practice for a beginner like me). BRUNO17’s code saved the day for me.

                  A logged in user can now create a page and supply all the content from a form and only that user can see an "edit" button that links to an edit form that, when filled out, changes the information of the template variables holding the page content.

                  Next I need to design the page and form to not be an ugly test-form/page, get the image option running and then get a logical search function running.

                  I’m going to have to do a lot of reading about ditto and ajaxsearch and decide which one would be best for a browse/search by category, name, date and rating function.

                  Thanks everyone for the help thus far.