Plugin Directory

Changeset 151781


Ignore:
Timestamp:
09/03/2009 12:45:28 PM (17 years ago)
Author:
pishmishy
Message:

Added ability to hide fields

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wordpress-petition-plugin/trunk/fcpetition.php

    r113974 r151781  
    102102                        `type`  VARCHAR(10),
    103103                        `opt`       TEXT,
     104                        `hide`  TINYINT(1),
    104105                        `ts`    TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    105106                        UNIQUE KEY name (petition,name)
     
    232233        $wpdb->get_results("ALTER TABLE $fields_table ADD `ts` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;");
    233234    }
     235    // Upgrade the petitions table if the hide field isn't present
     236    if($wpdb->get_var("SHOW COLUMNS FROM $fields_table LIKE 'hide'") != "hide") {
     237        $wpdb->get_results("ALTER TABLE $fields_table ADD `hide` TINYINT(1);");
     238    }
    234239    // Upgrade the signatures table if the keep_private column isn't present
    235240    if($wpdb->get_var("SHOW COLUMNS FROM $signature_table LIKE 'keep_private'") != "keep_private") {
     
    463468            }
    464469            if ($row->fields<>""){
    465                 $fields = fcpetition_prettyvalues(unserialize(base64_decode($row->fields)));
     470                $fields = fcpetition_prettyvalues(unserialize(base64_decode($row->fields)),$petition);
    466471            }
    467472            // Are comments enabled and a comment exists?
     
    917922 * Adds a custom field to the database
    918923 */
    919 function fcpetition_addfield($po,$fieldname,$fieldtype,$options){
     924function fcpetition_addfield($po,$fieldname,$fieldtype,$options,$hidefield){
    920925    global $wpdb;
    921926    global $fields_table;
    922     $sql = "INSERT into $fields_table (`petition`,`name`,`type`,`opt`) values ($po,'$fieldname','$fieldtype','$options')";
     927    $sql = "INSERT into $fields_table (`petition`,`name`,`type`,`opt`,`hide`) values ($po,'$fieldname','$fieldtype','$options','$hidefield')";
    923928    $wpdb->get_results($sql);
    924929}
     
    947952        ?>
    948953        <table>
    949             <tr><thead><th>Name</th><th>Type</th><th>Options</th><th></th></thead></tr>
     954            <tr><thead><th>Name</th><th>Type</th><th>Options</th><th>Printed</th><th></th></thead></tr>
    950955        <?php
    951956        foreach($res as $row){
     
    970975                </td>
    971976                <td>
     977                    <?php if($row->hide == 0) { ?>
     978                        No
     979                    <?php } else { ?>
     980                        Yes
     981                     <?php } ?>
     982                </td>                                                                                                                           
     983                <td>
    972984                    <form  method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>"/>
    973985                        <input type="hidden" name="fieldname" value="<?php echo $row->name; ?>"/>
     
    10091021    if(count($res)>0) {
    10101022        foreach($res as $row){
     1023            if($row->hide == 1) { $lmsg = __(" (won't be published)","fcpetition");} else { $lmsg = "";}
    10111024            if($row->type == "text") {
    1012                 $output .= "$row->name:<br/><input type='$row->type' name='$row->name'/><br/>\n";
     1025                $output .= "$row->name$lmsg:<br/><input type='$row->type' name='$row->name'/><br/>\n";
    10131026            } elseif($row->type == "select") {
    1014                 $output .= "$row->name:<br/><select name='$row->name'>";
     1027                $output .= "$row->name$lmsg:<br/><select name='$row->name'>";
    10151028                foreach(split(",",$row->opt) as $d){
    10161029                    $output .= "<option value='$d'>$d</option>\n";
     
    10621075                Name:<input type="text" name="fieldname"/>
    10631076                Options:<input type="text" name="options"/>
     1077                Publish field <input type="checkbox" name="hide" checked/>
    10641078                <input type="submit" name="Submit" value="<?php _e("Add","fcpetition")?>"/>
    10651079            </form>
     
    10771091}
    10781092
    1079 function fcpetition_prettyvalues($package) {
     1093function fcpetition_prettyvalues($package,$petition) {
     1094    global $wpdb;
     1095    global $fields_table;
    10801096    if(!$package) return;
     1097   
     1098    foreach($wpdb->get_results("SELECT name,hide FROM $fields_table WHERE petition = '$petition' ORDER BY ts") as $row) {
     1099        $hide[$row->name] = $row->hide;
     1100    }
     1101
     1102    foreach ($package as $fieldname => $fieldvalue){
     1103            if($hide[$fieldname] == 1) {
     1104                unset($package[$fieldname]);
     1105            }
     1106    }
     1107
    10811108    $custom_fields = "";
    10821109    $custom_fields = htmlchars(implode(", ",$package));
     
    11581185        $fieldtype = $wpdb->escape($_POST['fieldtype']);
    11591186        $fieldname = $wpdb->escape($_POST['fieldname']);
     1187        $fieldhide = $wpdb->escape($_POST['hide'])=='on'?1:0;
    11601188        $fieldoptions = $wpdb->escape($_POST['options']);
    1161         fcpetition_addfield($po,$fieldname,$fieldtype,$fieldoptions);
     1189        fcpetition_addfield($po,$fieldname,$fieldtype,$fieldoptions,$fieldhide);
    11621190    }
    11631191    if ( $_POST['deletefield']) {
Note: See TracChangeset for help on using the changeset viewer.