| 1 |
<?php |
| 2 |
|
| 3 |
class webling_page_memberlist_edit { |
| 4 |
public static function html () { |
| 5 |
global $wpdb; |
| 6 |
|
| 7 |
if (isset($_GET['list_id'])) { |
| 8 |
$id = intval($_GET['list_id']); |
| 9 |
} else { |
| 10 |
$id = 0; |
| 11 |
} |
| 12 |
|
| 13 |
try { |
| 14 |
$titlefields = WeblingApiHelper::Instance()->getMemberTitleFields(); |
| 15 |
} catch (Exception $e) { |
| 16 |
include_once(__DIR__.'/../errors/no_connection.html.php'); |
| 17 |
return; |
| 18 |
} |
| 19 |
|
| 20 |
if (!WeblingApiHelper::Instance()->hasMemberReadAccess()) { |
| 21 |
include_once(__DIR__.'/../errors/no_read_access.html.php'); |
| 22 |
WeblingApiHelper::Instance()->clearCache(); |
| 23 |
return; |
| 24 |
} |
| 25 |
|
| 26 |
if ($id) { |
| 27 |
$sql = "SELECT * FROM {$wpdb->prefix}webling_memberlists WHERE id = '".$id."'"; |
| 28 |
$data = $wpdb->get_row($sql, 'ARRAY_A'); |
| 29 |
if (!$data) { |
| 30 |
echo 'List with ID '.$id.' not found!'; |
| 31 |
return; |
| 32 |
} |
| 33 |
} else { |
| 34 |
$data = array( |
| 35 |
'id' => 0, |
| 36 |
'title' => __('Neue Liste', 'webling'), |
| 37 |
'show_all_groups' => 1, |
| 38 |
'groups' => '', |
| 39 |
'fields' => '', |
| 40 |
'sortorder' => 'ASC', |
| 41 |
'sortfield' => '', |
| 42 |
'class' => '', |
| 43 |
); |
| 44 |
|
| 45 |
$data['fields'] = json_encode($titlefields); |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
echo '<div class="wrap webling-admin">'; |
| 50 |
if ($id) { |
| 51 |
echo '<h2>'.__('Mitgliederliste bearbeiten', 'webling').' (ID: '.$id.')</h2>'; |
| 52 |
} else { |
| 53 |
echo '<h2>'.__('Mitgliederliste erstellen', 'webling').'</h2>'; |
| 54 |
} |
| 55 |
?> |
| 56 |
|
| 57 |
|
| 58 |
<form action="admin-post.php" method="post"> |
| 59 |
<input type="hidden" name="action" value="save_memberlist"> |
| 60 |
<input type="hidden" name="list_id" value="<?php echo $data['id']; ?>"> |
| 61 |
|
| 62 |
<div id="poststuff"> |
| 63 |
<div id="post-body" class="metabox-holder columns-2"> |
| 64 |
<div id="post-body-content"> |
| 65 |
|
| 66 |
<div id="titlediv"> |
| 67 |
<div id="titlewrap"> |
| 68 |
<input type="text" name="title" size="30" id="title" placeholder="<?php echo __('Listentitel', 'webling') ?>" spellcheck="true" autocomplete="off" value="<?php echo esc_attr($data['title']); ?>"> |
| 69 |
</div> |
| 70 |
</div> |
| 71 |
|
| 72 |
<div class="bodywrap"> |
| 73 |
|
| 74 |
<h3><?php echo __('Mitglieder anzeigen', 'webling') ?></h3> |
| 75 |
|
| 76 |
<div> |
| 77 |
<label> |
| 78 |
<input id="show_all_groups" onclick="toggle_groupselector()" type="checkbox" name="show_all_groups" <?php echo ($data['show_all_groups'] == 1 ? 'checked' : '') ?>> <?php echo __('Alle Mitglieder', 'webling') ?> |
| 79 |
</label> |
| 80 |
</div> |
| 81 |
|
| 82 |
<div id="groupselector"> |
| 83 |
<h4><?php echo __('Mitglieder aus folgenden Gruppen anzeigen:', 'webling') ?></h4> |
| 84 |
<?php echo self::groupselector(unserialize($data['groups'])) ?> |
| 85 |
</div> |
| 86 |
|
| 87 |
<h3><?php echo __('Angezeigte Felder und Reihenfolge festlegen', 'webling') ?></h3> |
| 88 |
<input type="hidden" id="fields" name="fields" value="<?php echo $data['fields']; ?>"> |
| 89 |
<ul id="sortable"> |
| 90 |
<?php |
| 91 |
$selectedFields = json_decode($data['fields']); |
| 92 |
if (!$selectedFields) { |
| 93 |
$selectedFields = []; |
| 94 |
} |
| 95 |
$memberfields = WeblingApiHelper::Instance()->getVisibleMemberFields(); |
| 96 |
foreach ($selectedFields as $field) { |
| 97 |
if (in_array($field, $memberfields)) { |
| 98 |
echo '<li class="selected sortable_field" data-field="'.esc_attr($field).'">' |
| 99 |
. '<span class="dashicons dashicons-move"></span> ' |
| 100 |
. '<input type="checkbox" checked="checked"/> ' |
| 101 |
. esc_html($field) |
| 102 |
. '</li>'; |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
foreach ($memberfields as $field) { |
| 107 |
if (!in_array($field, $selectedFields)) { |
| 108 |
echo '<li class="sortable_field" data-field="' . esc_attr($field) . '">' |
| 109 |
. '<span class="dashicons dashicons-move"></span> ' |
| 110 |
. '<input type="checkbox" /> ' |
| 111 |
. esc_html($field) |
| 112 |
. '</li>'; |
| 113 |
} |
| 114 |
} |
| 115 |
?> |
| 116 |
</ul> |
| 117 |
|
| 118 |
<?php |
| 119 |
if ($id) { |
| 120 |
submit_button(__('Liste speichern', 'webling'), 'primary', 'submit'); |
| 121 |
} else { |
| 122 |
submit_button(__('Liste erstellen', 'webling'), 'primary', 'submit'); |
| 123 |
} |
| 124 |
?> |
| 125 |
</div> |
| 126 |
</div> |
| 127 |
<div id="postbox-container-1" class="postbox-container"> |
| 128 |
<div id="side-sortables" class="meta-box-sortables"> |
| 129 |
<div id="submitdiv" class="postbox"> |
| 130 |
<h2 class="hndle"><span><?php echo __('Veröffentlichen', 'webling') ?></span></h2> |
| 131 |
<div class="inside"> |
| 132 |
<div class="submitbox" id="submitpost"> |
| 133 |
<div id="misc-publishing-actions"> |
| 134 |
<div class="misc-pub-section"> |
| 135 |
<?php if ($id) { ?> |
| 136 |
<p> |
| 137 |
<b><?php echo __('Shortcode', 'webling') ?></b> |
| 138 |
</p> |
| 139 |
<p><?php echo __('Füge diesen Shortcode in eine Seite oder einen Artikel ein um diese Liste anzuzeigen:', 'webling') ?></p> |
| 140 |
<p> |
| 141 |
<input title="Shortcode" class="shortcode" type="text" value='[webling_memberlist id="<?php echo $id; ?>"]'> |
| 142 |
</p> |
| 143 |
<?php } else { ?> |
| 144 |
<p><?php echo __('Nach dem Erstellen wird ein Shortcode erstellt, mit welchem du die Liste auf einer Seite oder in einem Artikel anzeigen kannst.', 'webling') ?></p> |
| 145 |
<?php } ?> |
| 146 |
</div> |
| 147 |
</div> |
| 148 |
<div id="major-publishing-actions"> |
| 149 |
<!--div id="delete-action"> |
| 150 |
<a class="submitdelete deletion" href="http://localhost/webling/wordpress-4.7.0/wp-admin/post.php?post=1&action=trash&_wpnonce=970d6cb90f">Move to Trash</a> |
| 151 |
</div--> |
| 152 |
<div id="publishing-action"> |
| 153 |
<input name="save" type="submit" class="button button-primary button-large" id="publish" value="<?php echo __('Speichern', 'webling') ?>"> |
| 154 |
</div> |
| 155 |
<div class="clear"></div> |
| 156 |
</div> |
| 157 |
</div> |
| 158 |
</div> |
| 159 |
</div> |
| 160 |
<div id="optionsdiv" class="postbox"> |
| 161 |
<h2 class="hndle"><span><?php echo __('Optionen', 'webling') ?></span></h2> |
| 162 |
<div class="inside"> |
| 163 |
<p class="post-attributes-label-wrapper"><label class="post-attributes-label" for="sortfield"> |
| 164 |
<?php echo __('Sortieren nach', 'webling') ?> |
| 165 |
</label></p> |
| 166 |
<?php echo self::fieldselector($data['sortfield'], 'sortfield'); ?> |
| 167 |
<select title="sort order" name="sortorder"> |
| 168 |
<option value="ASC" <?php echo ($data['sortorder'] == 'ASC' ? 'selected' : ''); ?>><?php echo __('aufsteigend [A-Z]', 'webling') ?></option> |
| 169 |
<option value="DESC" <?php echo ($data['sortorder'] == 'DESC' ? 'selected' : ''); ?>><?php echo __('absteigend [Z-A]', 'webling') ?></option> |
| 170 |
</select> |
| 171 |
|
| 172 |
<p class="post-attributes-label-wrapper"><label class="post-attributes-label" for="sortfield"> |
| 173 |
<?php echo __('Eigene CSS Klasse', 'webling') ?> |
| 174 |
</label></p> |
| 175 |
<input type="text" placeholder="<?php echo __('CSS Klasse', 'webling') ?>" name="class" value="<?php echo esc_attr($data['class']); ?>"> |
| 176 |
<p><?php echo __('Für eigene Designanpassungen', 'webling') ?></p> |
| 177 |
</div> |
| 178 |
</div> |
| 179 |
</div> |
| 180 |
</div> |
| 181 |
</div> |
| 182 |
</div> |
| 183 |
</form> |
| 184 |
|
| 185 |
</div> |
| 186 |
|
| 187 |
<script> |
| 188 |
jQuery(function() { |
| 189 |
jQuery( "#sortable" ).sortable({ |
| 190 |
stop: function (event, ui) { |
| 191 |
updateSortedMemberFields(); |
| 192 |
} |
| 193 |
}); |
| 194 |
jQuery( "#sortable" ).disableSelection(); |
| 195 |
|
| 196 |
jQuery( "#sortable input" ).change(function() { |
| 197 |
updateSortedMemberFields(); |
| 198 |
}); |
| 199 |
|
| 200 |
updateSortedMemberFields(); |
| 201 |
toggle_groupselector(); |
| 202 |
}); |
| 203 |
</script> |
| 204 |
|
| 205 |
<?php |
| 206 |
} |
| 207 |
|
| 208 |
protected static function fieldselector($selected, $inputname) { |
| 209 |
$fields = WeblingApiHelper::Instance()->getVisibleMemberFields(); |
| 210 |
$html = '<select name="'.$inputname.'" id="'.$inputname.'">'; |
| 211 |
foreach ($fields as $field) { |
| 212 |
$isSelected = ($field == $selected ? 'selected' : ''); |
| 213 |
$html .= '<option value="'.esc_attr($field).'" '.$isSelected.'>'.esc_html($field).'</option>'; |
| 214 |
} |
| 215 |
$html .= "</select>"; |
| 216 |
return $html; |
| 217 |
} |
| 218 |
|
| 219 |
protected static function groupselector($selected = []) { |
| 220 |
if (!$selected) { |
| 221 |
$selected = []; |
| 222 |
} |
| 223 |
$tree = WeblingApiHelper::Instance()->getMembergroupTree(); |
| 224 |
$html = ''; |
| 225 |
foreach ($tree as $nodeId => $node) { |
| 226 |
$html .= self::groupselectorRecursive($nodeId, $node, $selected); |
| 227 |
} |
| 228 |
return $html; |
| 229 |
} |
| 230 |
|
| 231 |
protected static function groupselectorRecursive($nodeId, $tree, $selected, $indent = 0) { |
| 232 |
$checked = (in_array($nodeId, $selected) ? 'checked' : ''); |
| 233 |
$html = '<div style="padding-left: '.($indent * 20).'px"> |
| 234 |
<label><input type="checkbox" name="groups['.$nodeId.']" '.$checked.'> '.esc_html($tree['title']) .'</label> |
| 235 |
</div>'; |
| 236 |
foreach ($tree['childs'] as $nodeId => $node) { |
| 237 |
$html .= self::groupselectorRecursive($nodeId, $node, $selected, $indent+1); |
| 238 |
} |
| 239 |
return $html; |
| 240 |
} |
| 241 |
} |
| 242 |
|
| 243 |
|
| 244 |
|