function wppa_album_sequence($parent) { global $wpdb; // Get the albums $albumorder = wppa_get_album_order($parent); $is_descending = strpos($albumorder, 'DESC') !== false; $albums = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . WPPA_ALBUMS . '` WHERE `a_parent` = %s ' . $albumorder, $parent), ARRAY_A); // Anything to do here ? if (empty($albums)) { return; } // Check my access rights foreach ($albums as $album) { if (!wppa_have_access($album['id'])) { return; } } // Check album order if (!strpos($albumorder, 'a_order')) { if ($parent == '0') { echo '<br />'; _e('You can edit top-level album sequence order here when you set the album order to "Order #" or "Order # desc" in Table IV-D1.'); } else { _e('You can edit sub-album sequence order here when you set the album order to "Order #" or "Order # desc" in the "Sub album sort order:" selection box above.'); } return; } echo '<h2>' . __('Manage album order', 'wp-photo-album-plus') . ' - ' . '<small>' . '<i>' . __('Change sequence order by drag and drop, or use the up/down arrows.', 'wp-photo-album-plus') . '</i>' . ' ' . __('Do not leave this page unless the bar is entirely green.', 'wp-photo-album-plus') . '</small>' . '</h2>'; echo '<table>' . '<thead>' . '<tr>' . '<th>' . __('Color', 'wp-photo-album-plus') . '</th>' . '<th>' . __('Meaning', 'wp-photo-album-plus') . '</th>' . '</tr>' . '</thead>' . '<tbody>' . '<tr>' . '<td>' . '<div style="background-color:green;height:12px;" ></div>' . '</td>' . '<td>' . __('Up to date', 'wp-photo-album-plus') . '</td>' . '</tr>' . '<tr>' . '<td>' . '<div style="background-color:yellow;height:12px;" ></div>' . '</td>' . '<td>' . __('Updating', 'wp-photo-album-plus') . '</td>' . '</tr>' . '<tr>' . '<td>' . '<div style="background-color:orange;height:12px;" ></div>' . '</td>' . '<td>' . __('Needs update', 'wp-photo-album-plus') . '</td>' . '</tr>' . '<tr>' . '<td>' . '<div style="background-color:red;height:12px;" ></div>' . '</td>' . '<td>' . __('Error', 'wp-photo-album-plus') . '</td>' . '</tr>' . '</tbody>' . '</table>'; ?> <style> .sortable-placeholder-albums { width: 100%; height: 60px; margin: 5px; border: 1px dotted #cccccc; border-radius:3px; float: left; } .ui-state-default-albums { position: relative; width: 100%; height: 60px; margin: 5px; border: 1px solid #cccccc; border-radius:3px; float: left; } .ui-state-default-albums td { padding:0; line-height:12px; text-align:center; } </style> <script> jQuery( function() { jQuery( "#sortable-albums" ).sortable( { cursor: "move", placeholder: "sortable-placeholder-albums", stop: function( event, ui ) { wppaDoRenumber(); } } ); } ); var wppaRenumberPending = false; var wppaAjaxInProgress = 0; function wppaDoRenumber() { // Busy? if ( wppaAjaxInProgress > 0 ) { wppaRenumberPending = true; } // Not busy else { _wppaDoRenumber(); } } function _wppaDoRenumber() { // Init var ids = jQuery( ".wppa-sort-item-albums" ); var seq = jQuery( ".wppa-sort-seqn-albums" ); var descend = <?php if ($is_descending) { echo 'true'; } else { echo 'false'; } ?> ; // Mark needs update var idx = 0; while ( idx < ids.length ) { var newvalue; if ( descend ) newvalue = ids.length - idx; else newvalue = idx + 1; var oldvalue = seq[idx].value; var album = ids[idx].value; if ( newvalue != oldvalue ) { jQuery( '#wppa-pb-'+idx ).css({backgroundColor:'orange'}); } idx++; } // Process var idx = 0; while ( idx < ids.length ) { var newvalue; if ( descend ) newvalue = ids.length - idx; else newvalue = idx + 1; var oldvalue = seq[idx].value; var album = ids[idx].value; if ( newvalue != oldvalue ) { wppaDoSeqUpdateAlbum( album, newvalue ); jQuery( '#wppa-pb-'+idx ).css({backgroundColor:'yellow'}); wppaLastAlbum = album; } idx++; } } function wppaDoSeqUpdateAlbum( album, seqno ) { var data = 'action=wppa' + '&wppa-action=update-album' + '&album-id=' + album + '&item=a_order' + '&wppa-nonce=' + document.getElementById( 'album-nonce-' + album ).value + '&value=' + seqno; var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if ( xmlhttp.readyState == 4 && xmlhttp.status != 404 ) { var ArrValues = xmlhttp.responseText.split( "||" ); if ( ArrValues[0] != '' ) { alert( 'The server returned unexpected output:\n' + ArrValues[0] ); } switch ( ArrValues[1] ) { case '0': // No error var i = seqno - 1; var descend = <?php if ($is_descending) { echo 'true'; } else { echo 'false'; } ?> ; if ( descend ) { i = <?php echo count($albums); ?> - seqno; } jQuery( '#wppa-album-seqno-' + album ).html( seqno ); if ( wppaRenumberPending ) { jQuery( '#wppa-pb-'+i ).css({backgroundColor:'orange'}); } else { jQuery( '#wppa-pb-'+i ).css({backgroundColor:'green'}); } if ( wppaLastAlbum = album ) { wppaRenumberBusy = false; } break; default: // Any error jQuery( '#wppa-album-seqno-' + album ).html( '<span style="color"red" >Err:' + ArrValues[1] + '</span>' ); break; } wppaAjaxInProgress--; // No longer busy? if ( wppaAjaxInProgress == 0 ) { if ( wppaRenumberPending ) { // Redo wppaRenumberPending = false; wppaDoRenumber(); } } } } xmlhttp.open( 'POST',wppaAjaxUrl,true ); xmlhttp.setRequestHeader( "Content-type","application/x-www-form-urlencoded" ); xmlhttp.send( data ); wppaAjaxInProgress++; jQuery( "#wppa-sort-seqn-albums-" + album ).attr( 'value', seqno ); // set hidden value to new value to prevent duplicate action var spinnerhtml = '<img src="' + wppaImageDirectory + 'spinner.gif' + '" />'; jQuery( '#wppa-album-seqno-' + album ).html( spinnerhtml ); } </script> <br /> <div id="wppa-progbar" style="width:100%;height:12px;" > <?php $c = count($albums); $l = 100 / $c; $i = 0; while ($i < $c) { echo '<div' . ' id="wppa-pb-' . $i . '"' . ' style="display:inline;float:left;background-color:green;height:12px;width:' . $l . '%;"' . ' >' . '</div>'; $i++; } ?> </div> <br /> <div class="widefat" style="max-width:600px;" > <div id="sortable-albums"> <?php foreach ($albums as $album) { $cover_photo_id = wppa_get_coverphoto_id($album['id']); echo ' <div' . ' id="albumitem-' . $album['id'] . '"' . ' class="ui-state-default-albums"' . ' style="background-color:#eeeeee;cursor:move;"' . ' >' . '<div' . ' style="height:100%;width:25%;float:left;text-align:center;overflow:hidden;" >'; if (wppa_is_video($cover_photo_id)) { echo wppa_get_video_html(array('id' => $cover_photo_id, 'height' => '50', 'margin_top' => '5', 'margin_bottom' => '5', 'controls' => false)); } else { echo '<img' . ' class="wppa-cover-image"' . ' src="' . wppa_fix_poster_ext(wppa_get_thumb_url(wppa_get_coverphoto_id($album['id'])), $cover_photo_id) . '"' . ' style="max-height:50px; margin: 5px;"' . ' />'; } echo '</div>' . '<div style="height:100%;width:40%;float:left;font-size:12px;overflow:hidden;" >' . '<b>' . wppa_get_album_name($album['id']) . '</b>' . '<br />' . wppa_get_album_desc($album['id']) . '</div>' . '<div style="float:right;width:10%;" >' . '<table>' . '<tr><td>' . '<img' . ' src="' . wppa_get_imgdir('up.png') . '"' . ' title="' . esc_attr(__('To top', 'wp-photo-album-plus')) . '"' . ' style="cursor:pointer;"' . ' onclick="' . 'jQuery( \'#albumitem-' . $album['id'] . '\' ).parent().prepend(jQuery( \'#albumitem-' . $album['id'] . '\' ));' . 'wppaDoRenumber();' . '"' . ' />' . '</td></tr>' . '<tr><td>' . '<img' . ' src="' . wppa_get_imgdir('up.png') . '"' . ' title="' . esc_attr(__('One up', 'wp-photo-album-plus')) . '"' . ' style="cursor:pointer;width:24px;"' . ' onclick="' . 'jQuery( \'#albumitem-' . $album['id'] . '\' ).prev().before(jQuery( \'#albumitem-' . $album['id'] . '\' ));' . 'wppaDoRenumber();' . '"' . ' />' . '</td></tr>' . '<tr><td>' . '<img' . ' src="' . wppa_get_imgdir('down.png') . '"' . ' title="' . esc_attr(__('One down', 'wp-photo-album-plus')) . '"' . ' style="cursor:pointer;width:24px;"' . ' onclick="' . 'jQuery( \'#albumitem-' . $album['id'] . '\' ).next().after(jQuery( \'#albumitem-' . $album['id'] . '\' ));' . 'wppaDoRenumber();' . '"' . ' />' . '</td></tr>' . '<tr><td>' . '<img' . ' src="' . wppa_get_imgdir('down.png') . '"' . ' title="' . esc_attr(__('To bottom', 'wp-photo-album-plus')) . '"' . ' style="cursor:pointer;"' . ' onclick="' . 'jQuery( \'#albumitem-' . $album['id'] . '\' ).parent().append(jQuery( \'#albumitem-' . $album['id'] . '\' ));' . 'wppaDoRenumber();' . '"' . ' />' . '</td></tr>' . '</table>' . '</div>' . '<div style="float:right; width:25%;" >' . '<span style=""> ' . __('Id:', 'wp-photo-album-plus') . ' ' . $album['id'] . '</span>' . '<span style=""> - ' . __('Ord:', 'wp-photo-album-plus') . '</span>' . '<span id="wppa-album-seqno-' . $album['id'] . '" > ' . $album['a_order'] . '</span>' . '<br />' . '<a href="' . wppa_ea_url($album['id']) . '" style="position:absolute;bottom:0;" >' . __('Edit', 'wp-photo-album-plus') . '</a>' . '</div>' . '<input type="hidden" id="album-nonce-' . $album['id'] . '" value="' . wp_create_nonce('wppa_nonce_' . $album['id']) . '" />' . '<input type="hidden" class="wppa-sort-item-albums" value="' . $album['id'] . '" />' . '<input type="hidden" class="wppa-sort-seqn-albums" id="wppa-sort-seqn-albums-' . $album['id'] . '" value="' . $album['a_order'] . '" />' . '</div>'; } ?> </div> <div style="clear:both;"></div> </div> <?php }
function wppa_do_albumlist($parent, $nestinglevel, $albums, $seq) { global $wpdb; $alt = true; foreach (array_keys($seq) as $s) { // Obey the global sequence $album = $albums[$s]; if ($album['a_parent'] == $parent) { if (wppa_have_access($album)) { $counts = wppa_treecount_a($album['id']); $pendcount = $counts['pendphotos']; $schedulecount = $counts['scheduledphotos']; $haschildren = wppa_have_accessable_children($album); $class = ''; if ($parent != '0' && $parent != '-1') { $class .= 'wppa-alb-on-' . $parent . ' '; $par = $parent; while ($par != '0' && $par != '-1') { $class .= 'wppa-alb-off-' . $par . ' '; $par = wppa_get_parentalbumid($par); } } if ($alt) { $class .= ' alternate'; } $style = ''; if ($pendcount) { $style .= 'background-color:#ffdddd; '; } // if ( $haschildren ) $style .= 'font-weight:bold; '; if ($parent != '0' && $parent != '-1') { $style .= 'display:none; '; } $onclickon = 'jQuery(\'.wppa-alb-on-' . $album['id'] . '\').css(\'display\',\'\'); jQuery(\'#alb-arrow-on-' . $album['id'] . '\').css(\'display\',\'none\'); jQuery(\'#alb-arrow-off-' . $album['id'] . '\').css(\'display\',\'\');'; $onclickoff = 'jQuery(\'.wppa-alb-off-' . $album['id'] . '\').css(\'display\',\'none\'); jQuery(\'#alb-arrow-on-' . $album['id'] . '\').css(\'display\',\'\'); jQuery(\'#alb-arrow-off-' . $album['id'] . '\').css(\'display\',\'none\'); checkArrows();'; $indent = $nestinglevel; if ($indent > '5') { $indent = 5; } ?> <tr class="<?php echo $class; ?> " style="<?php echo $style; ?> " > <?php $i = 0; while ($i < $indent) { echo '<td style="padding:2px;" ></td>'; $i++; } ?> <td style="padding:2px; text-align:center;" ><?php if ($haschildren) { ?> <img id="alb-arrow-off-<?php echo $album['id']; ?> " class="alb-arrow-off" style="height:16px; display:none;" src="<?php echo wppa_get_imgdir() . 'backarrow.gif'; ?> " onclick="<?php echo $onclickoff; ?> " title="<?php _e('Collapse subalbums', 'wp-photo-album-plus'); ?> " /> <img id="alb-arrow-on-<?php echo $album['id']; ?> " class="alb-arrow-on" style="height:16px;" src="<?php echo wppa_get_imgdir() . 'arrow.gif'; ?> " onclick="<?php echo $onclickon; ?> " title="<?php _e('Expand subalbums', 'wp-photo-album-plus'); ?> " /> <?php } ?> </td> <td style="padding:2px;" ><?php echo $album['id']; ?> </td> <?php $i = $indent; while ($i < 5) { echo '<td style="padding:2px;" ></td>'; $i++; } ?> <td><?php echo esc_attr(__(stripslashes($album['name']))); ?> </td> <td><small><?php echo esc_attr(__(stripslashes($album['description']))); ?> </small></td> <?php if (current_user_can('administrator')) { ?> <td><?php echo $album['owner']; ?> </td> <?php } ?> <td><?php echo $album['a_order']; ?> </td> <td><?php echo wppa_get_album_name($album['a_parent'], 'extended'); ?> </td> <?php $url = wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_admin_menu&tab=edit&edit_id=' . $album['id']); ?> <?php $na = $counts['selfalbums']; ?> <?php $np = $counts['selfphotos']; ?> <?php $nm = $counts['pendphotos']; ?> <?php $ns = $counts['scheduledphotos']; ?> <td><?php echo $na . '/' . $np . '/' . $nm . '/' . $ns; ?> </td> <?php if ($album['owner'] != '--- public ---' || wppa_user_is('administrator')) { ?> <?php $url = wppa_ea_url($album['id']); ?> <td><a href="<?php echo $url; ?> " class="wppaedit"><?php _e('Edit', 'wp-photo-album-plus'); ?> </a></td> <td><a href="<?php echo $url . '&quick'; ?> " class="wppaedit"><?php _e('Quick', 'wp-photo-album-plus'); ?> </a></td> <td><a href="<?php echo $url . '&bulk#manage-photos'; ?> " class="wppaedit"><?php _e('Bulk', 'wp-photo-album-plus'); ?> </a></td> <td><a href="<?php echo $url . '&seq'; ?> " class="wppaedit"><?php _e('Seq', 'wp-photo-album-plus'); ?> </a></td> <?php $url = wppa_ea_url($album['id'], 'del'); ?> <td><a href="<?php echo $url; ?> " class="wppadelete"><?php _e('Delete', 'wp-photo-album-plus'); ?> </a></td> <?php if (wppa_can_create_album()) { $url = wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_admin_menu&tab=edit&edit_id=new&parent_id=' . $album['id']); if (wppa_switch('confirm_create')) { $onc = 'if (confirm(\'' . __('Are you sure you want to create a subalbum?', 'wp-photo-album-plus') . '\')) document.location=\'' . $url . '\';'; echo '<td><a onclick="' . $onc . '" class="wppacreate">' . __('Create', 'wp-photo-album-plus') . '</a></td>'; } else { echo '<td><a href="' . $url . '" class="wppacreate">' . __('Create', 'wp-photo-album-plus') . '</a></td>'; } } } else { ?> <td></td><td></td><?php if (wppa_can_create_album()) { echo '<td></td'; } ?> <?php } ?> </tr> <?php if ($alt == '') { $alt = ' class="alternate" '; } else { $alt = ''; } if ($haschildren) { wppa_do_albumlist($album['id'], $nestinglevel + '1', $albums, $seq); } } } } }
function wppa_album_sequence($parent) { global $wpdb; // Get the albums $albumorder = wppa_get_album_order($parent); $is_descending = strpos($albumorder, 'DESC') !== false; $albums = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . WPPA_ALBUMS . '` WHERE `a_parent` = %s ' . $albumorder, $parent), ARRAY_A); // Anything to do here ? if (empty($albums)) { return; } // Check my access rights foreach ($albums as $album) { if (!wppa_have_access($album['id'])) { return; } } // Check album order if (!strpos($albumorder, 'a_order')) { if ($parent == '0') { echo '<br />'; _e('You can edit top-level album sequence order here when you set the album order to "Order #" or "Order # desc" in Table IV-D1.'); } else { _e('You can edit sub-album sequence order here when you set the album order to "Order #" or "Order # desc" in the "Sub album sort order:" selection box above.'); } return; } echo '<h2>' . __('Manage album order', 'wp-photo-album-plus') . ' - ' . '<small><i>' . __('Change sequence order by drag and drop', 'wp-photo-album-plus') . '</i></small>' . '</h2>'; ?> <style> .sortable-placeholder-albums { width: 100%; height: 60px; margin: 5px; border: 1px dotted #cccccc; border-radius:3px; float: left; } .ui-state-default-albums { position: relative; width: 100%; height: 60px; margin: 5px; border: 1px solid #cccccc; border-radius:3px; float: left; } </style> <script> jQuery( function() { jQuery( "#sortable-albums" ).sortable( { cursor: "move", placeholder: "sortable-placeholder-albums", stop: function( event, ui ) { var ids = jQuery( ".wppa-sort-item-albums" ); var seq = jQuery( ".wppa-sort-seqn-albums" ); var idx = 0; var descend = <?php if ($is_descending) { echo 'true'; } else { echo 'false'; } ?> ; while ( idx < ids.length ) { var newvalue; if ( descend ) newvalue = ids.length - idx; else newvalue = idx + 1; var oldvalue = seq[idx].value; var album = ids[idx].value; if ( newvalue != oldvalue ) { wppaDoSeqUpdateAlbum( album, newvalue ); } idx++; } } } ); } ); function wppaDoSeqUpdateAlbum( album, seqno ) { var data = 'action=wppa' + '&wppa-action=update-album' + '&album-id=' + album + '&item=a_order' + '&wppa-nonce=' + document.getElementById( 'album-nonce-' + album ).value + '&value=' + seqno; var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if ( xmlhttp.readyState == 4 && xmlhttp.status != 404 ) { var ArrValues = xmlhttp.responseText.split( "||" ); if ( ArrValues[0] != '' ) { alert( 'The server returned unexpected output:\n' + ArrValues[0] ); } switch ( ArrValues[1] ) { case '0': // No error jQuery( '#wppa-album-seqno-' + album ).html( seqno ); break; default: // Any error jQuery( '#wppa-album-seqno-' + album ).html( '<span style="color"red" >Err:' + ArrValues[1] + '</span>' ); break; } } } xmlhttp.open( 'POST',wppaAjaxUrl,true ); xmlhttp.setRequestHeader( "Content-type","application/x-www-form-urlencoded" ); xmlhttp.send( data ); jQuery( "#wppa-sort-seqn-albums-" + album ).attr( 'value', seqno ); // set hidden value to new value to prevent duplicate action var spinnerhtml = '<img src="' + wppaImageDirectory + 'wpspin.gif' + '" />'; jQuery( '#wppa-album-seqno-' + album ).html( spinnerhtml ); } </script> <div class="widefat" style="max-width:500px;" > <div id="sortable-albums"> <?php foreach ($albums as $album) { echo ' <div' . ' id="albumitem-' . $album['id'] . '"' . ' class="ui-state-default-albums"' . ' style="background-color:#eeeeee;cursor:move;"' . ' >' . '<div' . ' style="height:100%;width:25%;float:left;text-align:center;overflow:hidden;" >' . '<img' . ' class="wppa-cover-image"' . ' src="' . wppa_fix_poster_ext(wppa_get_thumb_url(wppa_get_coverphoto_id($album['id'])), wppa_get_coverphoto_id($album['id'])) . '"' . ' style="max-height:50px; margin: 5px;"' . ' />' . '</div>' . '<div style="height:100%;width:50%;float:left;font-size:12px;overflow:hidden;" >' . '<b>' . wppa_get_album_name($album['id']) . '</b>' . '<br />' . wppa_get_album_desc($album['id']) . '</div>' . '<div style="float:right; width:25%;" >' . '<span style=""> ' . __('Id:', 'wp-photo-album-plus') . ' ' . $album['id'] . '</span>' . '<span style=""> - ' . __('Ord:', 'wp-photo-album-plus') . '</span>' . '<span id="wppa-album-seqno-' . $album['id'] . '" > ' . $album['a_order'] . '</span>' . '<br />' . '<a href="' . wppa_ea_url($album['id']) . '" style="position:absolute;bottom:0;" >' . __('Edit', 'wp-photo-album-plus') . '</a>' . '</div>' . '<input type="hidden" id="album-nonce-' . $album['id'] . '" value="' . wp_create_nonce('wppa_nonce_' . $album['id']) . '" />' . '<input type="hidden" class="wppa-sort-item-albums" value="' . $album['id'] . '" />' . '<input type="hidden" class="wppa-sort-seqn-albums" id="wppa-sort-seqn-albums-' . $album['id'] . '" value="' . $album['a_order'] . '" />' . '</div>'; } ?> </div> <div style="clear:both;"></div> </div> <?php }