We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31037
    • 358 Posts
    The same file exists in the zip at the first post, you could try that one.

    I have a friend with a mac, I will ask him for assistance smiley

    I’ll get back to you when I get hold of him.
      • 31037
      • 358 Posts
      Quote from: lukwe at Nov 13, 2006, 03:25 PM
      ...I’m getting an error when unzipping the new file: 0.1.1_beta_ppp.resources.inc.zip with Stuffit on MacOs 10.4
      You might have solved it already, but I’m attaching a archive made in a Mac.

      Note to others: This file is just for upgrading, download file in first post for a new install.

      Soon I release a new version with picture management, just have to solve some Safe Mode issues. Have a pretty well working solution on the (ugly) demo site.

      EDIT: File removed, use latest version from first post in this thread.
        • 17673
        • 194 Posts
        Thanks for the new file... if it was the same as the original one there was no need to update it.


        Anyhow I am now trying out PPP and got very confused in step 1&2 (creating custom fields); it now works, but I got very confused about the siteAdmin user vs webUsers permissions...

        I ended up with the page being assigned to a document group for which only the Admin as privileges (as you state in the instructions), but in order to see the PPP form to add custom fields etc I have to log into the front-end as a web-user WHILE the siteadmin is logged into the manager [?!??]
        accessing the page when just the site admin is logged in the manager gives me no PPP output, accessing it as a web-user when the site admin is logged out returns the 404 page
        Is this OK ?!? it does prevent a generic web-user to add custom fields from its own machine without having the admin password (or the admin itself on his/her side) but it just feels awkward ..!

        Changing the published/unpublished checkbox for the document seems to have no effect on the above behaviours.

        Still have to try step 3,4,5,6 ...

        ciao!



          ----------------------------------------------------------
          http://www.linkedin.com/in/lucapost/
          http://www.twitter.com/lukwe/
          ----------------------------------------------------------
          • 34017
          • 898 Posts
          Anders,

          I don’t know how pretty it is, but I have a working solution that allows the user to choose the type of column and attributes they wish to use.

          There is a new parameter on line 38 of ppp.inc.php (in case you want to use allow some Admins to add custom fields and not others:
          /*Set different types of columns*/
          $ppp_allowCustomColumns = isset($allowCustomColumns) ? $allowCustomColumns : 0;
          


          I also added "$ppp_allowCustomColumns;" to the GLOBALS of ppp.inc.php (I dont know if this is needed or not).

          In ppp.resources.inc.ppp, I modified the function ppp_addCustomField to:
          	function ppp_addCustomField() {
          		
          		global $modx, $ppp_useTable, $table_prefix, $ppp_allowCustomColumns;
          
          		if ($ppp_useTable=='0') {
          			
          			echo 'To be able to add fields you must first define a table to use in your ppp snippet call.';
          			
          		} else {
          			
          			?>
          
          			<form method="post" id="ppp_addFieldForm" action="[~[*id*]~]">
          				[+msgSuccess+]
          
          				<p>Add a new field to your selected custom table <?php echo '"' . $ppp_useTable . '".'; ?> 
          				<br />This will also create a placeholder with the same name.</p>
          
          				<p><label accesskey="a" for="ppp_addField">Name of new field:</label>
          				<input type="text" name="ppp_addField" maxlength="60" /></p>
          
          				<?php if ($ppp_allowCustomColumns=='1') { ?>
          					<script type="text/javascript">
          					<!--
          					
          					function init()
          					{
          						if (!document.layers) return;
          						var box = document.forms[0].elements;
          						for (var i=0;i<box.length;i++)
          						{
          							box[i].disabled = false;
          						}
          					}
          					
          					function disableIt(obj)
          					{
          						obj.disabled = !(obj.disabled);
          						var z = (obj.disabled) ? 'disabled' : 'enabled';
          						alert(obj.name + ' is now ' + z + '.\n\n This setting is only recommended for users who know what you are doing ' );
          					}
          					
          					function extracheck(obj)
          					{
          						return !obj.disabled;
          					}
          					// -->
          					</script>
          				<p><label accesskey="b" for="ppp_customColumnType">Custom column type:</label>
          
          				<input name="ppp_customColumnType" type="text" value="" disabled="true" onkeydown="return extracheck(this)" />
          				<a href="javascript:disableIt(document.forms[0].ppp_customColumnType)">Disable/enable</a></p>
          				<?php } ?>
          
          				<p><input type="submit" name="submit" value="Send/Skicka"></p>
          
          			</form>
          			<?php
          				if (isset($_POST[ppp_customColumnType]) && $ppp_allowCustomColumns=='1') {
          					$customCol = $modx->db->escape($_POST[ppp_customColumnType]);
          				} else {
          					$customCol = 'TINYTEXT NOT NULL';
          				}
          
          				// TODO: Should be expanded to create different kind of fields
          				if (isset($_POST[ppp_addField])) {
          					//TODO: Escape is not good for adding a new column name. What to do? Only admin will add, but should be safe anyway.
          					$addCol = $modx->db->escape($_POST[ppp_addField]);
          					$table = $table_prefix.$ppp_useTable;
          					$sql = "ALTER TABLE ". $table . " ADD COLUMN " . $addCol. " " . $customCol;
          								
          					$result = $modx->db->query($sql);
          					if ($result=1) {
          						$msg = '<p><em>Your new field "'.$addCol . '" was added to the "'.$ppp_useTable.'" table and is now avalible as a placeholder together with the ones listed below.</em></p>';
          						$modx->setPlaceholder('msgSuccess', $msg);
          					}
          				}
          		}	
          	}	 
          


          How to use:
          1. Examples. Put the following in "Custom column type" input box:
          - For VARCHAR of 255, put "VARCHAR( 255 ) CHARACTER NOT NULL"
          - For INT(10), put "INT( 10 ) DEFAULT 0 NOT NULL" (notice there is no ’ around the number. It will not work with them)

          Hope this works for you. And my code is probably bad too. Sorry.

          Chuck
            Chuck the Trukk
            ProWebscape.com :: Nashville-WebDesign.com
            - - - - - - - -
            What are TV's? Here's some info below.
            http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
            http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008
            • 31037
            • 358 Posts
            Quote from: ProWebscape at Nov 14, 2006, 08:49 PM
            Chuck! Fantastic! I’ll test it in a few hours! Just have some "in-real-life" stuff to do first, like eat some food smiley

            Quote from: lukwe at Nov 14, 2006, 02:55 PM
            Anyhow I am now trying out PPP and got very confused in step 1&2 (creating custom fields); it now works, but I got very confused about the siteAdmin user vs webUsers permissions...
            Lukwe:, in this the first version I just made the "new add field" the easiest way, just to see if the concept would work.

            Thanks to Chuck the add field functionality is lightyears better, but we still have to think about how this functionality should work for admins.

            At this point I would not let anyone else but the site creator come near the add new field (PPP Admin) page.

            And also, keep in mind that nothing in PPP at this point works inside manager, or with manager users. You should for now just give your self access to the PPP Admin page, and that would be done in the front-end.

            Easiest might be to create your own web users group/document group with only your self in it, and assign the PPP Admin to that group. You could then keep it visible in menu.

            IMPORTANT: If you use rc2 of 0.95 there will be some problems, see separate post.

            it does prevent a generic web-user to add custom fields
            To be extra clear, it is not meant that end users (registered users) will be able to add fields. Would be useless, as they would have to create eForm fields, in other words, the visitors of the site would make their own sites tongue (Actually, I’m planning to add functionality for users to "style" their profile pages, and also add new fields. But it will be done in a different way.)

            I’ll try to make this more clear in the next version of the documentation.

            If you still have questions, don’t hesitate to ask!
              • 31037
              • 358 Posts
              Quote from: ProWebscape at Nov 14, 2006, 08:49 PM
              I don’t know how pretty it is, but I have a working solution that allows the user to choose the type of column and attributes they wish to use.
              Chuck, this was really needed, and also on my todo list.

              The solution I was going to implement for this was unnecessary complex and would have taking me a long time to write, so I’m very glad you made it. Gives me more time for working with image handling. (Have you checked the demo recently? Solution is not ready for releasing yet though...)

              Just one problem, I can’t get it to work. It is disabled by the javascript no matter what I do. In FF js-console it says "obj has no properties". I haven’t yet started to study js, so I don’t know what the problem could be.

              I guess it is ok I use your solution in PPP? With credit to you of course!
                • 34017
                • 898 Posts
                Anders,

                Of course it is okay to use my solution. I got to benefit from your work freely- I give you my little mod freely. The reason I hadn’t been using MODx was because their was no easy way to do what PPP is doing.

                I want to help you however I can. The code you created was incredibly easy to work with.

                I am no javascript guru either. I just did a search on enable disable javascript. Here is the page I got the code from: http://www.quirksmode.org/js/disabled.html

                The javascript can be pretty annoying, so I am working on a config option to enable/disable it.

                Chuck
                  Chuck the Trukk
                  ProWebscape.com :: Nashville-WebDesign.com
                  - - - - - - - -
                  What are TV's? Here's some info below.
                  http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
                  http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008
                  • 31037
                  • 358 Posts
                  Quote from: ProWebscape at Nov 15, 2006, 08:07 PM


                  The reason I hadn’t been using MODx was because their was no easy way to do what PPP is doing.

                  Chuck, those words really inspires me to keep working with PPP. Very nice to know that my little snippet can make someone start using MODx! smiley

                  (Note to others, the rest of this post is a code discussion.)

                  About the javascript, yes it would be better not to use javascrip in the code at all, at least for me smiley

                  I saw your post in another thread about calling with multiple options. I actually have made someting like this in PPP, but not released it yet. Here is the code:

                  EDIT: Chuck, I now see this wasn’t exactly what you where asking about in the other thread, but maybe you find it interesting anyway.

                  In ppp.inc.php
                  // A comma delimited list of fields that must be filled in for the user to show up in the user links list
                  $ppp_listUsersWithFields = isset($listUsersWithFields) ? $listUsersWithFields : false;


                  In ppp.resources.inc.php
                  //Determins if user should be shown in the link list, based on if required fields filled in
                  function ppp_onlyWithFields($userId, $withFields, $useTable) {
                  	
                  	GLOBAL $modx;
                  	
                  	//How many fields are set as required in the snippet call? Use later to compare  
                  	$arrUseFields = explode(',', str_replace(' ', '', $withFields)); //we need to be sure about spaces and count number of field names
                  	$wordCountWithFields = count($arrUseFields); 
                  	
                  		//Let's check how many of required fields that are set by current user
                  		$selectFields = implode(', ',$arrUseFields); //Format for the select				
                  		$where = "webuser=" .$userId;
                  		$table = $modx->getFullTableName($useTable);
                  		$results = $modx->db->select($selectFields, $table, $where);
                  
                  		//Now let's do the actual count of how many field values are set
                  		$wordCountTblFields = 0;
                  		$row = $modx->db->getRow($results);
                  			if (is_array($row)) {
                  				foreach($row as $value) {if (!$value=='') ++$wordCountTblFields;}
                  				return ($wordCountTblFields == $wordCountWithFields) ? true : false ;
                  			} else {
                  				return false;
                  			}	
                  				
                  }
                  


                  This is a function within the ppp_showListOfUsers function that determines if a user should be in the user links list, set by an extra parameter in the ppp call: &listUsersWithFields=`eyecolor, food, music`

                  I forgot, here is the changed list creator loop with the call to the extra function above.

                  				while ($row = $modx->db->getRow($rs)) {
                  					$userName = $row['username'];
                  					$userId = $row['id'];
                  						//if mandatory fields are set in ppp call: exclude some users from list
                  						if ($withFields) {
                  							if (!ppp_onlyWithFields($userId, $withFields, $useTable)) continue;
                  						}	
                  					$ppp_PhListUsers .= '<a href="[~'. $directTo .'~]'.$arg.'WID=' . $userId . '">' . $userName . '</a><br />';
                  				}


                  If you want the complete updated files, just let me know. The new code is not ready for release yet though.

                  I also saw your post asking about how to store and read multi valued form fields to/from database, I’ll try to find time this weekend to create an example of that which works well together with PPP/eform.

                  Thanks,

                  Anders
                    • 17673
                    • 194 Posts

                    I am sorry not to have enough time to contribute a little to this much needed snippet!

                    Just an observation about the general approach though: maybe it would be better to have PPP creating a document with its own ID for each user, this way the site admin can then make other things happen for users by just using the IDs in Snippet calls on a users-specific template...


                    Ciao

                      ----------------------------------------------------------
                      http://www.linkedin.com/in/lucapost/
                      http://www.twitter.com/lukwe/
                      ----------------------------------------------------------
                      • 34017
                      • 898 Posts
                      Edit: I removed my post because it was so buggy it wasn’t funny. Am refactoring now.

                      Anders,

                      I am thinking of removing the PrimaryKey option (would anyone set this to other than id)?

                      PS - To better view print_r(array, use
                      echo ’<pre>’;
                      print_r(array($_POST));
                      echo ’</pre>’;
                        Chuck the Trukk
                        ProWebscape.com :: Nashville-WebDesign.com
                        - - - - - - - -
                        What are TV's? Here's some info below.
                        http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
                        http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008