...I’m getting an error when unzipping the new file: 0.1.1_beta_ppp.resources.inc.zip with Stuffit on MacOs 10.4You might have solved it already, but I’m attaching a archive made in a Mac.
/*Set different types of columns*/ $ppp_allowCustomColumns = isset($allowCustomColumns) ? $allowCustomColumns : 0;
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); } } } }
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.
it does prevent a generic web-user to add custom fieldsTo 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 (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 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.
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!
The reason I hadn’t been using MODx was because their was no easy way to do what PPP is doing.
// 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;
//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; } }
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 />'; }