Changeset 151781
- Timestamp:
- 09/03/2009 12:45:28 PM (17 years ago)
- File:
-
- 1 edited
-
wordpress-petition-plugin/trunk/fcpetition.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wordpress-petition-plugin/trunk/fcpetition.php
r113974 r151781 102 102 `type` VARCHAR(10), 103 103 `opt` TEXT, 104 `hide` TINYINT(1), 104 105 `ts` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 105 106 UNIQUE KEY name (petition,name) … … 232 233 $wpdb->get_results("ALTER TABLE $fields_table ADD `ts` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;"); 233 234 } 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 } 234 239 // Upgrade the signatures table if the keep_private column isn't present 235 240 if($wpdb->get_var("SHOW COLUMNS FROM $signature_table LIKE 'keep_private'") != "keep_private") { … … 463 468 } 464 469 if ($row->fields<>""){ 465 $fields = fcpetition_prettyvalues(unserialize(base64_decode($row->fields)) );470 $fields = fcpetition_prettyvalues(unserialize(base64_decode($row->fields)),$petition); 466 471 } 467 472 // Are comments enabled and a comment exists? … … 917 922 * Adds a custom field to the database 918 923 */ 919 function fcpetition_addfield($po,$fieldname,$fieldtype,$options ){924 function fcpetition_addfield($po,$fieldname,$fieldtype,$options,$hidefield){ 920 925 global $wpdb; 921 926 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')"; 923 928 $wpdb->get_results($sql); 924 929 } … … 947 952 ?> 948 953 <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> 950 955 <?php 951 956 foreach($res as $row){ … … 970 975 </td> 971 976 <td> 977 <?php if($row->hide == 0) { ?> 978 No 979 <?php } else { ?> 980 Yes 981 <?php } ?> 982 </td> 983 <td> 972 984 <form method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>"/> 973 985 <input type="hidden" name="fieldname" value="<?php echo $row->name; ?>"/> … … 1009 1021 if(count($res)>0) { 1010 1022 foreach($res as $row){ 1023 if($row->hide == 1) { $lmsg = __(" (won't be published)","fcpetition");} else { $lmsg = "";} 1011 1024 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"; 1013 1026 } elseif($row->type == "select") { 1014 $output .= "$row->name :<br/><select name='$row->name'>";1027 $output .= "$row->name$lmsg:<br/><select name='$row->name'>"; 1015 1028 foreach(split(",",$row->opt) as $d){ 1016 1029 $output .= "<option value='$d'>$d</option>\n"; … … 1062 1075 Name:<input type="text" name="fieldname"/> 1063 1076 Options:<input type="text" name="options"/> 1077 Publish field <input type="checkbox" name="hide" checked/> 1064 1078 <input type="submit" name="Submit" value="<?php _e("Add","fcpetition")?>"/> 1065 1079 </form> … … 1077 1091 } 1078 1092 1079 function fcpetition_prettyvalues($package) { 1093 function fcpetition_prettyvalues($package,$petition) { 1094 global $wpdb; 1095 global $fields_table; 1080 1096 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 1081 1108 $custom_fields = ""; 1082 1109 $custom_fields = htmlchars(implode(", ",$package)); … … 1158 1185 $fieldtype = $wpdb->escape($_POST['fieldtype']); 1159 1186 $fieldname = $wpdb->escape($_POST['fieldname']); 1187 $fieldhide = $wpdb->escape($_POST['hide'])=='on'?1:0; 1160 1188 $fieldoptions = $wpdb->escape($_POST['options']); 1161 fcpetition_addfield($po,$fieldname,$fieldtype,$fieldoptions );1189 fcpetition_addfield($po,$fieldname,$fieldtype,$fieldoptions,$fieldhide); 1162 1190 } 1163 1191 if ( $_POST['deletefield']) {
Note: See TracChangeset
for help on using the changeset viewer.