web/wp-content/plugins/gigs-calendar/archive.ajax.php
branchwordpress
changeset 112 fb7cd02b9848
parent 111 6b96085291d7
child 123 561aa6d282f6
equal deleted inserted replaced
111:6b96085291d7 112:fb7cd02b9848
     1 <?php
       
     2 
       
     3 require_once 'ajaxSetup.php';
       
     4 $pageTarget = $folder . 'archive.ajax.php';
       
     5 
       
     6 switch ($_POST['action']) {
       
     7 	case 'load':
       
     8 		$v = new venue();
       
     9 		$g = new gig();
       
    10 		$p = new performance();
       
    11 		$g->search("date <= CURDATE()", 'date DESC');
       
    12 		?>
       
    13 			<table id="gig-list" class="gigs widefat">
       
    14 				<thead>
       
    15 					<tr>
       
    16 						<th style="text-align: center;" scope="col"><?php _e('ID', $gcd) ?></th>
       
    17 						<th scope="col"><?php _e('Venue', $gcd) ?></th>
       
    18 						<th scope="col"><?php _e('City', $gcd) ?></th>
       
    19 						<th scope="col"><?php _e('Date', $gcd) ?></th>
       
    20 						<th scope="col"><?php _e('Time', $gcd) ?></th>
       
    21 						<th style="text-align: center" scope="col"><?php _e('Actions', $gcd) ?></th>
       
    22 					</tr>
       
    23 				</thead>
       
    24 				<tbody>
       
    25 					<?php while ( $g->fetch() ) : $v = $g->getVenue(); $p = $g->getPerformances(); $post = get_post($g->postID);?>
       
    26 						<tr id="gig-<?php echo $g->id; ?>" class="gig gig-<?php echo $g->id; ?> <?php echo ++$count % 2 ? "alternate" : "";?>">
       
    27 							<th style="text-align: center;" scope="row"><?php echo $g->id; ?></th>
       
    28 							<td class="venue"><?php echo $v->name; ?></td>
       
    29 							<td class="city"><?php echo $v->city . (!empty($v->state) ? ', ' . $v->state :  '') ?></td>
       
    30 							<td class="date"><?php echo $g->date ?></td>
       
    31 							<td class="time">
       
    32 								<?php if ( $p ) : while ( $p->fetch() ) : ?>
       
    33 									<span class="time"><?php echo dtcGigs::timeFormat($p->time) ?></span>
       
    34 								<?php endwhile; endif; ?>
       
    35 							</td>
       
    36 							<td class="actions" style="text-align: center; position: relative;">
       
    37 								<div style="position: relative">
       
    38 									<a target="_blank" class="guid" href="<?php echo $g->getPermalink(); ?>"><img alt="<?php _e('View Gig', $gcd) ?>" title="<?php _e('View Gig', $gcd) ?>" class="clickable view" src="<?php echo $folder; ?>images/page_white_magnify.png" /></a>
       
    39 									<img alt="<?php _e('Edit', $gcd) ?>" title="<?php _e('Edit', $gcd) ?>" class="clickable edit" src="<?php echo $folder; ?>images/page_white_edit.png" />
       
    40 									<?php if ( $v ) : ?>
       
    41 										<a target="_blank" href="<?php echo $v->getMapLink(); ?>"><img alt="<?php _e('Map', $gcd) ?>" title="<?php _e('Map', $gcd) ?>" class="clickable map" src="<?php echo $folder; ?>images/world.png" /></a>
       
    42 									<?php endif ?>
       
    43 									<a target="_blank" href="<?php echo get_option('siteurl') ?>/wp-admin/post.php?action=edit&post=<?php echo $post->ID; ?>">
       
    44 										<img alt="<?php _e('Edit WordPress Post', $gcd) ?>" title="<?php _e('Edit WordPress Post', $gcd) ?>" class="clickable edit-post" src="<?php echo $folder; ?>images/page_edit.png" />
       
    45 									</a>
       
    46 									<img alt="<?php _e('Delete', $gcd) ?>" title="<?php _e('Delete', $gcd) ?>" class="clickable delete" src="<?php echo $folder; ?>images/delete.png" />
       
    47 								</div>
       
    48 							</td>
       
    49 						</tr>
       
    50 						<tr id="gig-panel-<?php echo $g->id; ?>" class="gig gig-<?php echo $g->id; ?> panel <?php echo $count % 2 ? "alternate" : "";?>">
       
    51 							<td style="background-color: white"></td>
       
    52 							<td class="panel" colspan="5"></td>
       
    53 						</tr>
       
    54 					<?php endwhile; ?>
       
    55 				</tbody>
       
    56 			</table>
       
    57 				
       
    58 			<script type="text/javascript">
       
    59 			
       
    60 				(function($){
       
    61 					$("#add-venue").click(function(){
       
    62 						gigs_page_load("venues", "new=1");
       
    63 					});
       
    64 					
       
    65 					$("#gig-add-trigger").click(function(){
       
    66 						$("#gig-add-form:hidden").slideDown(300, function(){
       
    67 							$("#new-name").focus();
       
    68 						});
       
    69 					});
       
    70 					
       
    71 					$("#new-gig-reset").click(function(){
       
    72 						$("#gig-add-form table.performance[id!=performance-c1]").parents("tr").remove();
       
    73 						$("#gig-add-form").slideUp(300);
       
    74 					});
       
    75 					
       
    76 					$("#new-date").datepicker({dateFormat:"yy-mm-dd"});
       
    77 					$(".date-field").datepicker({dateFormat:"yy-mm-dd"});
       
    78 					
       
    79 					
       
    80 					$("#new-gig").ajaxForm({
       
    81 						url:pageTarget,
       
    82 						dataType: "json",
       
    83 						success:function(json){
       
    84 							gigs = $("table#gig-list tbody tr:not(.panel) td.date");
       
    85 							inserted = false;
       
    86 							for ( i = 0; i < gigs.length; i++ ) {
       
    87 								if ( json.gig.date < gigs.eq(i).html() ) {
       
    88 									g = gigs.eq(i);
       
    89 									$.post(pageTarget, {
       
    90 										nonce:nonce,
       
    91 										action:'getRow',
       
    92 										id:json.gig.id
       
    93 									}, function(rsp){
       
    94 										g.parents("tr").before(rsp);
       
    95 										resetTableColors("table#gig-list");
       
    96 									});
       
    97 									inserted = true;
       
    98 									break;
       
    99 								}
       
   100 							}
       
   101 							if ( !inserted ) {
       
   102 								$.post(pageTarget, {
       
   103 									nonce:nonce,
       
   104 									action:'getRow',
       
   105 									id:json.gig.id
       
   106 								}, function(rsp){
       
   107 									$("table#gig-list tbody").append(rsp);
       
   108 									resetTableColors("table#gig-list");
       
   109 								});
       
   110 							}
       
   111 							$("#new-gig-reset").click();
       
   112 						}
       
   113 
       
   114 					});
       
   115 					
       
   116 					setupPerformanceRemoval = function() {
       
   117 						$("div.delete-performance img").unbind("click");
       
   118 						$("div.delete-performance img").click(function(){
       
   119 							id = $(this).parents("tr").eq(0).find("input.performanceID").val();
       
   120 							if ( id == "" ) {
       
   121 								$(this).parents("tr").eq(1).remove();
       
   122 							} else {
       
   123 								if ( confirm("<?php _e('Are you sure you want to remove this performance?', $gcd) ?>") ) {
       
   124 									$(this).parents("form").children(".extra-inputs").append('<input type="hidden" name="delete[]" value="' + id + '" />');
       
   125 									$(this).parents("tr").eq(1).remove();
       
   126 								}
       
   127 							}
       
   128 						});
       
   129 					}
       
   130 					
       
   131 					setupPerformances = function() {
       
   132 						$(".add-performance").unbind("click");
       
   133 						$(".add-performance").click(function(){
       
   134 							td = $(this).parents("tr").eq(0).before("<tr><td colspan='2'><div class='loading'><img src='<?php echo $folder; ?>images/ajax-loader.gif' alt='' /></div></td></tr>").prev().children("td").load(pageTarget,{
       
   135 								nonce:nonce,
       
   136 								action:"performance-form",
       
   137 								count:$(this).parents("table").eq(0).find("table.performance").length + 1
       
   138 							}, setupPerformanceRemoval);
       
   139 						});
       
   140 						setupPerformanceRemoval();
       
   141 
       
   142 					}
       
   143 					
       
   144 					setupEvents = function() {
       
   145 						$("img.delete").unbind("click");
       
   146 						$("img.delete").click(function(){
       
   147 							id = $(this).parents("tr").attr("id").split("-")[1];
       
   148 							$.post(pageTarget, {
       
   149 								nonce:nonce,
       
   150 								action:'delete',
       
   151 								id:id
       
   152 							});
       
   153 							$(this).parents("tr").next().remove();
       
   154 							$(this).parents("tr").remove();
       
   155 							resetTableColors("table#gig-list");
       
   156 						});
       
   157 						
       
   158 						$("img.edit").unbind("click");
       
   159 						$("img.edit").click(function(){
       
   160 							row = $(this).parents("tr");
       
   161 							id = row.attr("id").split("-")[1];
       
   162 							row.next().children("td.panel").load(pageTarget, {
       
   163 								nonce:nonce,
       
   164 								action:"edit",
       
   165 								id:id
       
   166 							}, function(){
       
   167 								row.next().css("display", "table-row");
       
   168 							});
       
   169 						});
       
   170 						
       
   171 						setupPerformances();
       
   172 					}
       
   173 					
       
   174 					setupEvents();
       
   175 
       
   176 				}(jQuery));
       
   177 				
       
   178 			
       
   179 			
       
   180 			</script>
       
   181 		<?php
       
   182 		break;
       
   183 	case 'delete':
       
   184 		$g = new gig($_POST['id']);
       
   185 		$result = $g->delete();
       
   186 		echo '{"success": ' . ($result ? 'true' : 'false') . ',"action":"delete"' . ($result ? '' : ',"error":"db"') . '}';
       
   187 		break;
       
   188 	case 'edit':
       
   189 		$g = new gig($_POST['id']);
       
   190 		$p = $g->getPerformances();
       
   191 		$v = $g->getVenue();
       
   192 		?>
       
   193 			<form id="edit-gig-<?php echo $g->id ?>" class="edit-item" method="post" action="<?php echo $pageTarget; ?>">
       
   194 				<table>
       
   195 					<tbody>
       
   196 						<tr><td colspan="2">
       
   197 							<h3 class="no-margin"><?php _e('Gig Information', $gcd) ?></h3>
       
   198 							<div class="instructions"><?php _e('A "gig" is unique to a date at a venue.', $gcd) ?></div>
       
   199 						</td></tr>
       
   200 						<tr class="venue">
       
   201 							<td><label for="new-venue"><?php _e('Venue:', $gcd) ?></label></td>
       
   202 							<td>
       
   203 								<?php echo $v->name . ' - ' . $v->getCity() ?>
       
   204 							</td>
       
   205 						</tr>
       
   206 						<tr class="date">
       
   207 							<td><label for="new-date"><?php _e('Date:', $gcd) ?></label></td>
       
   208 							<td><input type="text" class="date wide" name="date" id="edit-date-<?php echo $g->id ?>" value="<?php echo $g->date ?>" /></td>
       
   209 						</tr>
       
   210 						<tr class="eventName">
       
   211 							<td><label for="edit-eventName-<?php echo $g->id ?>"><?php _e('Event Name:', $gcd) ?></label></td>
       
   212 							<td><input type="text" class="eventName wide" name="eventName" id="edit-eventName-<?php echo $g->id ?>" value="<?php echo $g->eventName ?>" /></td>
       
   213 						</tr>
       
   214 						<tr class="tour">
       
   215 							<td><label for="edit-tour_id-<?php echo $g->id ?>"><?php _e('Tour:', $gcd) ?></label></td>
       
   216 							<td class="tour">
       
   217 								<select class="tour_id" name="tour_id" id="edit-tour_id-<?php echo $g->id ?>">
       
   218 									<option value="-1"><?php _e("--None--", $gcd); ?></option>
       
   219 									<?php $t = new tour(); $t->search(null, '`name`'); ?>
       
   220 									<?php while ( $t->fetch() ) : ?>
       
   221 										<option value="<?php echo $t->id; ?>" <?php if ( $g->tour_id == $t->id ) echo 'selected="selected"'; ?>><?php echo $t->name; ?></option>
       
   222 									<?php endwhile; ?>
       
   223 								</select>
       
   224 							</td>
       
   225 						</tr>
       
   226 						<?php if ( function_exists('wp_set_post_tags') ) : ?>
       
   227 							<tr class="tags">
       
   228 								<td><label for="edit-tags-<?php echo $g->id ?>"><?php _e('Post Tags:', $gcd) ?></label></td>
       
   229 								<td><input type="text" class="tags wide" name="tags" id="edit-tags-<?php echo $g->id ?>" value="<?php echo dtcGigs::escapeForInput(implode(', ', $g->getTags())) ?>" /></td>
       
   230 							</tr>
       
   231 						<?php endif; ?>
       
   232 						<tr class="notes"><td colspan="2">
       
   233 							<?php _e('Description/Other notes:', $gcd) ?><br />
       
   234 							<textarea class="notes" name="notes" rows="8" cols="80"><?php echo $g->notes ?></textarea>
       
   235 						</td></tr>
       
   236 						
       
   237 						<?php if ( $wp_version >= 2.5 ) : ?>
       
   238 							<?php 
       
   239 								$metadata = get_post_custom($g->postID);
       
   240 								dtcGigs::extraFields(apply_filters('gigCal_gigs_extraFields', array()), $metadata, $g->id);
       
   241 							?>
       
   242 							<tr><td colspan="2">
       
   243 								<div id="postcustom-<?php echo $g->id ?>" class="postcustom">
       
   244 									<h3 title="<?php _e('Click to expand', $gcd); ?>" class="clickable"><?php _e('Custom Fields') ?> <img class="inline-icon" src="<?php echo $folder ?>images/plus.gif" alt="<?php _e('Expand', $gcd); ?>"> <img class="inline-icon" style="display:none;" src="<?php echo $folder ?>images/minus.gif" alt="<?php _e('Collapse', $gcd); ?>"></h3>
       
   245 									<div class="inside">
       
   246 										<div id="postcustomstuff-<?php echo $g->id ?>">
       
   247 										<table cellpadding="3">
       
   248 											<thead>
       
   249 												<tr>
       
   250 													<th><?php _e('Key', $gcd) ?></th>
       
   251 													<th><?php _e('Value', $gcd) ?></th>
       
   252 													<th></th>
       
   253 												</tr>
       
   254 											</thead>
       
   255 											<tbody>
       
   256 												<?php
       
   257 													$metadata = get_post_custom($g->postID);
       
   258 													foreach ( $metadata as $key => $values ) {
       
   259 														foreach ( $values as $index => $value ) {
       
   260 															if ( substr($key, 0, 1) != '_' ) {
       
   261 																?><tr>
       
   262 																	<td><input value="<?php echo addslashes($key) ?>" name="custom-key[]" /></td>
       
   263 																	<td>
       
   264 																		<textarea rows="1" name="custom-value[]"><?php echo htmlspecialchars($value) ?></textarea>
       
   265 																		<textarea style="display:none;" rows="1" name="old-custom-value[]"><?php echo htmlspecialchars($value) ?></textarea>
       
   266 																		<input class="delete" type="hidden" name="deletecustom[]" value="0" />
       
   267 																	</td>
       
   268 																	<td><img alt="<?php _e('Remove Custom Field', $gcd) ?>" title="<?php _e('Remove Custom Field', $gcd) ?>" class="clickable delete-custom" src="<?php echo $folder; ?>images/delete.png" /></td>
       
   269 																</tr><?php
       
   270 															}
       
   271 														}
       
   272 													}
       
   273 												?>
       
   274 											</tbody>
       
   275 										</table>
       
   276 										<div class="custom-ajax-response"></div>
       
   277 										</div>
       
   278 										<p>
       
   279 											<span class="clickable add-custom-field">
       
   280 												<img class="inline-icon" src="<?php echo $folder ?>images/add.png" alt="" />
       
   281 												<?php _e('Add a new custom field'); ?>
       
   282 											</span>
       
   283 										</p>
       
   284 										<p><?php _e('Custom fields can be used to add extra metadata to a gig that you can use in a special template.'); ?></p>
       
   285 									</div>
       
   286 								</div>
       
   287 							</td></tr>
       
   288 						<?php endif; ?>
       
   289 						
       
   290 						<tr><td colspan="2">
       
   291 							<h3 class="no-margin"><?php _e('Performances', $gcd) ?></h3>
       
   292 							<div class="instructions"><?php _e('You can add as many performances as<br />you are giving at a venue on the given date.', $gcd) ?></div>
       
   293 						</td></tr>
       
   294 						<?php while ( $p->fetch() ) : ?>
       
   295 							<tr><td colspan="2">
       
   296 								<?php pForm($p->id, false) ?>
       
   297 							</td></tr>
       
   298 						<?php endwhile ?>
       
   299 						<tr><td colspan="2">
       
   300 							<div class="clickable add-performance"><img class="icon" src="<?php echo $folder; ?>images/add.png" /> <?php _e('Add another performance', $gcd) ?></div>
       
   301 						</td></tr>
       
   302 
       
   303 					</tbody>
       
   304 				</table>
       
   305 				<div class="extra-inputs">
       
   306 					<input type="submit" class="button" name="" value="<?php _e('Save Gig', $gcd); ?>" />
       
   307 					<input type="reset" class="button cancel" name="" value="<?php _e('Cancel', $gcd); ?>" id="edit-gig-reset-<?php echo $g->id ?>" />
       
   308 					<input type="hidden" name="action" value="save" />
       
   309 					<input type="hidden" name="id" value="<?php echo $g->id ?>" />
       
   310 					<input type="hidden" name="nonce" value="<?php echo $_POST['nonce']; ?>" />
       
   311 				</div>
       
   312 			</form>
       
   313 			
       
   314 			<script type="text/javascript">
       
   315 				(function($){
       
   316 					(function(form) { // Function to let a plugin add extra JS code to process the form.
       
   317 						<?php do_action('gigCal_gigs_formExtraJS'); ?>
       
   318 					}($("#edit-gig-<?php echo $g->id ?>")));
       
   319 
       
   320 					$("#edit-gig-<?php echo $g->id ?> .add-custom-field").click(function(){
       
   321 						$("#edit-gig-<?php echo $g->id ?> .postcustom table").append('<tr><td><input value="" name="custom-key[]" /></td><td><textarea rows="1" name="custom-value[]"></textarea><textarea style="display:none;" rows="1" name="old-custom-value[]"></textarea><input class="delete" type="hidden" name="deletecustom[]" value="0" /></td><td><img class="delete-custom" alt="<?php _e('Remove Custom Field', $gcd) ?>" title="<?php _e('Remove Custom Field', $gcd) ?>" class="clickable" src="<?php echo $folder; ?>images/delete.png" /></td></tr>');
       
   322 						
       
   323 						$("#edit-gig-<?php echo $g->id ?> .delete-custom").unbind("click");
       
   324 						$("#edit-gig-<?php echo $g->id ?> .delete-custom").click(function(){
       
   325 							$(this).parents("tr").eq(0).remove();
       
   326 						});
       
   327 					});
       
   328 					
       
   329 					$("#edit-gig-<?php echo $g->id ?> .delete-custom").click(function(){
       
   330 						$(this).parents("td").eq(0).siblings().children("input.delete").val(1);
       
   331 						$(this).parents("tr").eq(0).hide();
       
   332 					});
       
   333 					
       
   334 					$("#postcustom-<?php echo $g->id ?> h3.clickable").click(function(){
       
   335 						$(this).next().toggle();
       
   336 						$(this).children(".inline-icon").toggle();
       
   337 					});
       
   338 
       
   339 
       
   340 				
       
   341 					$("#edit-gig-<?php echo $g->id ?> .date").datepicker({dateFormat:"yy-mm-dd"});
       
   342 					$(".date-field").datepicker({dateFormat:"yy-mm-dd"});
       
   343 					setupPerformances();
       
   344 					
       
   345 					$("#edit-gig-reset-<?php echo $g->id ?>").click(function(){
       
   346 						$(this).parents("tr.panel").hide();
       
   347 					});
       
   348 					
       
   349 					$("#edit-gig-<?php echo $g->id ?>").ajaxForm({
       
   350 						url:pageTarget,
       
   351 						dataType: "json",
       
   352 						success:function(json){
       
   353 							row = $("#gig-panel-" + json.gig.id).hide().prev();
       
   354 							row.children("td.date").html(json.gig.date);
       
   355 							row.find("a.guid").attr("href", json.gig.permalink);
       
   356 							times = row.children("td.time");
       
   357 							times.html("");
       
   358 							for ( i = 0; i < json.gig.performances.length; i++ ) {
       
   359 								time = json.gig.performances[i].time.split(":");
       
   360 								<?php if ( $options['time-12h'] ) : ?>
       
   361 									if ( time[0] == 0 ) {
       
   362 										time[0] = 12;
       
   363 										time[2] = 'am';
       
   364 									} else if ( time[0] == 12 ) {
       
   365 										time[2] = 'pm';
       
   366 									} else if ( time[0] < 12 ) {
       
   367 										time[2] = 'am';
       
   368 									} else if ( time[0] > 12 ) {
       
   369 										time[0] = time[0] - 12;
       
   370 										time[2] = 'pm';
       
   371 									}
       
   372 									times.append('<span class="time">' + time[0] + ':' + time[1] + time[2] + '</span> ');
       
   373 								<?php else : ?>
       
   374 									times.append('<span class="time">' + time[0] + ':' + time[1] + '</span> ');
       
   375 								<?php endif; ?>
       
   376 							}
       
   377 							
       
   378 						}
       
   379 					});
       
   380 				}(jQuery));
       
   381 			</script>
       
   382 		<?php
       
   383 		break;
       
   384 		
       
   385 	case 'save':
       
   386 		$g = new gig($_POST['id']);
       
   387 		$g->date = $_POST['date'];
       
   388 		$g->notes = $_POST['notes'];
       
   389 		$g->setTags($_POST['tags']);
       
   390 		$g->eventName = $_POST['eventName'];
       
   391 
       
   392 		if ( isset($_POST['performanceID']) ) {
       
   393 			foreach ( $_POST['performanceID'] as $key => $pid ) {
       
   394 				$p = new performance((empty($pid) ? null : $pid));
       
   395 				$p->gigID = $g->id;
       
   396 				$p->link = $_POST['link'][$key];
       
   397 				$p->shortNotes = $_POST['shortNotes'][$key];
       
   398 				$p->ages = (empty($_POST['ages-custom'][$key]) ? $_POST['ages'][$key] : $_POST['ages-custom'][$key]);
       
   399 				$p->time = date("H:i:s", strtotime($_POST['hour'][$key] . ':' . $_POST['minute'][$key] . ' ' . $_POST['meridiem'][$key]));
       
   400 				$p->save();
       
   401 			}
       
   402 		}
       
   403 		
       
   404 		$p = new performance();
       
   405 		if ( isset($_POST['delete']) ) {
       
   406 			foreach ( $_POST['delete'] as $pid ) {
       
   407 				$p->get($pid);
       
   408 				$p->delete();
       
   409 			}
       
   410 		}
       
   411 		
       
   412 		$g->save();
       
   413 		
       
   414 		foreach ( $_POST['deletecustom'] as $key => $delete ) {
       
   415 			if ( $delete ) {
       
   416 				delete_post_meta($g->postID, $_POST['custom-key'][$key], $_POST['old-custom-value'][$key]);
       
   417 			}
       
   418 		}
       
   419 		
       
   420 		foreach ( $_POST['custom-key'] as $key => $field ) {
       
   421 				if ( is_array($_POST['custom-value'][$key]) ) {
       
   422 					foreach ( $_POST['custom-value'][$key] as $k => $v ) {
       
   423 						if ( $v === "" ) {
       
   424 							unset($_POST['custom-value'][$key][$k]);
       
   425 						}
       
   426 					}
       
   427 				}
       
   428 				if ( empty($_POST['custom-value'][$key]) && empty($_POST['old-custom-value'][$key]) ) {
       
   429 					// If both value fields are empty, just ignore this field.
       
   430 					continue;
       
   431 				} elseif ( $_POST['custom-value'][$key] === "" ) {
       
   432 					// If the old value is not empty, but the new one is, delete this sucker.
       
   433 					delete_post_meta($g->postID, $_POST['custom-key'][$key], $_POST['old-custom-value'][$key]);
       
   434 				} elseif ( $_POST['old-custom-value'][$key] === "" ) {
       
   435 					// If the old value is empty, but the new one is not, create a new custom field.
       
   436 					add_post_meta($g->postID, $_POST['custom-key'][$key], $_POST['custom-value'][$key]);
       
   437 				} elseif ( $_POST['old-custom-value'][$key] != $_POST['custom-value'][$key] && $_POST['old-custom-value'][$key] != serialize($_POST['custom-value'][$key]) ) {
       
   438 					// If the old and new values are not equal, update the custom field.
       
   439 					update_post_meta($g->postID, $_POST['custom-key'][$key], $_POST['custom-value'][$key], unserialize($_POST['old-custom-value'][$key]));
       
   440 				}
       
   441 		}
       
   442 
       
   443 		echo '{success:true, gig:' . $g->toJSON() . '}';
       
   444 		break;
       
   445 		
       
   446 	case 'performance-form':
       
   447 		if ( isset($_POST['id']) ) {
       
   448 			pForm($_POST['id'], false);
       
   449 		} else {
       
   450 			pForm((int) $_POST['count'], true);
       
   451 		}
       
   452 		break;
       
   453 }
       
   454 
       
   455 
       
   456 function pForm($id, $new = true, $remove = true) {
       
   457 	global $folder, $gcd, $options;
       
   458 	$p = new performance();
       
   459 	if ( $new ) {
       
   460 		$count = 'c' . $id;
       
   461 	} else {
       
   462 		$p->get($id);
       
   463 		$count = 'id' . $id;
       
   464 	}
       
   465 	
       
   466 	$ages = $options['ages-list'];
       
   467 	
       
   468 	$time = explode(":", $p->time);
       
   469 	$minutes = $time[1];
       
   470 	
       
   471 	if ( $options['time-12h'] ) {
       
   472 		if ( $time[0] == 0 ) {
       
   473 			$hour = "12";
       
   474 			$meridiem = "AM";
       
   475 		} elseif ( $time[0] == 12 ) {
       
   476 			$hour = "12";
       
   477 			$meridiem = "PM";
       
   478 		} elseif ( $time[0] < 12 ) {
       
   479 			$hour = $time[0];
       
   480 			$meridiem = "AM";
       
   481 		} else {
       
   482 			$hour = $time[0] - 12;
       
   483 			$meridiem = "PM";
       
   484 		}
       
   485 	} else { 
       
   486 		$hour = $time[0];
       
   487 	}
       
   488 	?>
       
   489 		<table id="performance-<?php echo $count ?>" class="performance performance-<?php echo $count ?> <?php if ( $new ) echo 'new' ?>"><tbody>
       
   490 			<tr>
       
   491 				<td>
       
   492 					<label>
       
   493 						<input type="hidden" class="performanceID" name="performanceID[]" value="<?php echo $p->id; ?>" />
       
   494 						<?php _e('Performance Time:', $gcd) ?>
       
   495 					</label>
       
   496 				</td><td>
       
   497 					<div>
       
   498 						<select name="hour[]">
       
   499 							<?php for ( $i = 1; $i <= ($options['time-12h'] ? 12 : 23); $i++ ) : ?>
       
   500 								<option <?php if ( $i == $hour ) echo 'selected="selected"' ?>><?php echo $i ?></option>
       
   501 							<?php endfor; ?>
       
   502 						</select>
       
   503 						<select name="minute[]">
       
   504 							<option <?php if ( "00" == $minutes ) echo 'selected="selected"' ?>>00</option>
       
   505 							<option <?php if ( "15" == $minutes ) echo 'selected="selected"' ?>>15</option>
       
   506 							<option <?php if ( "30" == $minutes ) echo 'selected="selected"' ?>>30</option>
       
   507 							<option <?php if ( "45" == $minutes ) echo 'selected="selected"' ?>>45</option>
       
   508 							<option value="00">--</option>
       
   509 							<?php for ( $i = 0; $i <= 59; $i++ ) : ?>
       
   510 								<option <?php if ( !in_array($i, array("00", "15", "30", "45")) && $i == $minutes ) echo 'selected="selected"' ?>><?php echo str_pad($i, 2, STR_PAD_LEFT, '0') ?></option>
       
   511 							<?php endfor; ?>
       
   512 						</select>
       
   513 						<?php if ( $options['time-12h'] ) : ?>
       
   514 							<select name="meridiem[]">
       
   515 								<option <?php if ( 'AM' == $meridiem ) echo 'selected="selected"' ?>><?php _e('AM', $gcd) ?></option>
       
   516 								<option <?php if ( 'PM' == $meridiem ) echo 'selected="selected"' ?>><?php _e('PM', $gcd) ?></option>
       
   517 							</select>
       
   518 						<?php else : ?>
       
   519 							<input type="hidden" name="meridiem[]" value="" />
       
   520 						<?php endif; ?>
       
   521 						<?php if ( $remove ) : ?>
       
   522 							<div class="delete-performance"><img alt="<?php _e('Remove Performance', $gcd) ?>" title="<?php _e('Remove Performance', $gcd) ?>" class="clickable" src="<?php echo $folder; ?>images/delete.png" /></div>
       
   523 						<?php endif ?>
       
   524 					</div>
       
   525 				</td>
       
   526 			</tr><tr>
       
   527 				<td>
       
   528 					<label for="performance-link[]"><?php _e('External Link (for tickets):', $gcd) ?></label>
       
   529 				</td><td>
       
   530 					<input type="text" class="link wide" name="link[]" id="performance-link[]" value="<?php echo $p->link ?>" />
       
   531 				</td>
       
   532 			</tr><tr>
       
   533 				<td>
       
   534 					<label for="performance-shortNotes-<?php echo $count; ?>"><?php _e('Short Notes:', $gcd) ?></label>
       
   535 				</td><td>
       
   536 					<input type="text" class="shortNotes wide" name="shortNotes[]" id="performance-shortNotes-<?php echo $count; ?>" value="<?php echo $p->shortNotes ?>" />
       
   537 				</td>
       
   538 			</tr><tr>
       
   539 				<td>
       
   540 					<label for="performance-ages-<?php echo $count; ?>"><?php _e('Ages:', $gcd) ?></label>
       
   541 				</td><td>
       
   542 					<select name="ages[]" id="performance-ages-<?php echo $count; ?>">
       
   543 						<?php $found = false; foreach ( $ages as $age ) : ?>
       
   544 							<option <?php if ( $p->ages == $age ) {echo 'selected="selected"'; $found = true;} ?>><?php echo $age ?></option>
       
   545 						<?php endforeach; ?>
       
   546 					</select>
       
   547 					<?php _e('Or...', $gcd) ?>
       
   548 					<input type="text" class="ages" name="ages-custom[]" id="performance-ages-custom[]" value="<?php if ( !$found ) echo $p->ages; ?>" />
       
   549 				</td>
       
   550 			</tr>
       
   551 		</tbody></table>
       
   552 		<script type="text/javascript">
       
   553 		</script>
       
   554 	<?php
       
   555 }
       
   556 ?>