cman /common/script.php

Language PHP Lines 744
MD5 Hash f281f7d08e67bb237d903e4941aaf419 Estimated Cost $444 (why?)
Repository https://bitbucket.org/14rego/cman.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
<div id="dialog-edit-team"></div>
<div id="dialog-edit-note"></div>
<div id="dialog-edit-task"></div>
<div id="dialog-edit-link"></div>
<div id="dialog-view-log"></div>
<div id="dialog-loading"></div>

<script>
$.sendMsg = function(thisTITLE, thisMSG){
	if (thisTITLE==='error') {
		var thisTITLE = 'Error.';
		var thisMSG = 'Sorry, there has been an error: ['+thisMSG+']';
	} else {
		$.gritter.add({ title: thisTITLE, text: thisMSG, class_name: 'gritter-light' }); return false;
	}
};
$.quickUpdate = function(tab, col, val, id, act, itemLIST, itemTYPE){
	var serialData = 't='+tab+'&c='+col+'&v='+val+'&i='+id+'&a='+act;
	$.post('/manage/forms/update.php', serialData)
		.success(function(data) { 
			if (itemLIST!=='success' && itemTYPE!=='msg') { $.updatePageData(itemLIST, itemTYPE); }
			$.sendMsg('Success', 'Update successful.');
		})
		.error(function(data) { $.sendMsg('error'); });
};
$.resetDefaults = function(list, filter){
	$('#filter-select-client').val('ALL');
	$('#filter-select-status').val('');
	$('#filter-select-label').val('');
	$('#filter-select-type').val('');
	$('#filter-select-priority').val('');
	$('#filter-select-from').val('');
	$('#filter-select-to').val('');
	$('#filter-select-sort').val('');
	$('#filter-select-in').val('');
	$('#filter-search').val('');
	// OVERRIDE DEFAULTS
	if (list==='users-rows') {
		$('#filter-select-type').val('all');
		$('#filter-select-sort').val('lastn');
	} else if (list==='logins-rows') {
		$('#filter-select-sort').val('url');
		$('#filter-select-in').val('ASC');
	} else if (list==='jobs-rows') {
		$('#filter-select-status').val('active');
		$('#filter-select-sort').val('proj.due');
		$('#filter-select-in').val('ASC');
	} else if (list==='costs-rows') {
		$('#filter-select-status').val('in queue');
		$('#filter-select-sort').val('cost.dat');
		$('#filter-select-in').val('DESC');
	} else if (list==='web-traffic-filters-rows') {
		$('#filter-select-client').val('Competition');
	}
	$.updatePageData(list, filter);
};
$.updatePageData = function(list, filter){
	var parentID	= $('#'+filter+'_id').val();
	var setCLIENT	= $('#filter-select-client').val();
	var setSTATUS	= $('#filter-select-status').val();
	var setCAT	= $('#filter-select-label').val();
	var setTYPE	= $('#filter-select-type').val();
	var setPRI	= $('#filter-select-priority').val();
	var setFROM	= $('#filter-select-from').val();
	var setTO		= $('#filter-select-to').val();
	var setSORT	= $('#filter-select-sort').val();
	var setIN		= $('#filter-select-in').val();
	var setSEARCH	= $('#filter-search').val();
	
	if (list==='checklist-stickies' || list==='tasks-stickies') { <?php 
		if ($contents=='checklist' || $contents=='tasks') { ?>
			if (list==='checklist-stickies') { 
				var setTYPE = 'checklist';
				var setQUERY = '&src='+setSEARCH+'&frm='+setFROM+'&to='+setTO+'&tem=<?php echo $user_name; ?>&cat='+setCAT+'&pri='+setPRI;
				var setPARENT = '.lanes';
				var thisTYPE = 'todo';
			} else {
				var setTYPE = 'tasks'; 
				var setQUERY = '&src='+setSEARCH+'&in='+setIN+'&frm='+setFROM+'&to='+setTO+'&cli='+setCLIENT+'&pri='+setPRI;
				var setPARENT = '.lane';
				var thisTYPE = 'task';
			} <?php 
			pg_result_seek($result, 0);
			while ($lane = pg_fetch_array($result)) { ?>
				var serialData = '<?php echo 'status='.$lane['alt']; ?>'+setQUERY;
				$.get('/manage/rows/'+setTYPE+'-stickies.php', serialData)
					.success(function(data) { 
						$('#trello .<?php echo $lane['alt']; ?>').html(data);
						<?php if ($mobility!='desktop') { ?>
						$('.drag-it h3 a').hammer().unbind('dragend').delay(500).bind('dragend',function(e){
							e.preventDefault();
							var itemID = $(this).closest('.sticky').attr('id');
							var thisSTATUS = $(this).closest(setPARENT).attr('alt');
							var thisEV = e.direction;
							if		(thisEV==='left') { var thisDIR = 'L'; }
							else if	(thisEV==='right') { var thisDIR = 'R'; }
							if (thisDIR==='L' || thisDIR==='R') {
								var serialData = 'i='+itemID+'&t='+thisTYPE+'&c=status&v='+thisSTATUS+'&a='+thisDIR;
								$.post('/manage/forms/update.php', serialData)
									.success(function(data) { 
										$(this).unbind('dragend');
										$.updatePageData(setTYPE+'-stickies');
									})
									.error(function(data) { $.sendMsg('error'); });
							}
							return false;
						});
						<?php } ?>
					})
					.error(function(data) { $.sendMsg('error'); });
				<?php 
			}
		} ?>
	} else if (list==='checklist-edit') {
		var serialData = 'cat=todo&type=lane';
		$.get('/manage/rows/pman-settings-rows.php', serialData)
			.success(function(data) { 
				$('#holder-todo-lanes').html(data);
			})
			.error(function(data) { $.sendMsg('error'); });
		var serialData = 'cat=todo&type=label';
		$.get('/manage/rows/pman-settings-rows.php', serialData)
			.success(function(data) { 
				$('#holder-todo-labels').html(data);
			})
			.error(function(data) { $.sendMsg('error'); });
	} else if (list==='work-edit-rows') {
		var serialData = 'cat=work&type=client';
		$.get('/manage/rows/pman-settings-rows.php', serialData)
			.success(function(data) { 
				$('#holder-work-clients-rows').html(data);
			})
			.error(function(data) { $.sendMsg('error'); });
		var serialData = 'cat=work&type=cat';
		$.get('/manage/rows/pman-settings-rows.php', serialData)
			.success(function(data) { 
				$('#holder-work-cats-rows').html(data);
			})
			.error(function(data) { $.sendMsg('error'); });
		var serialData = 'cat=work&type=pri';
		$.get('/manage/rows/pman-settings-rows.php', serialData)
			.success(function(data) { 
				$('#holder-work-pris-rows').html(data);
			})
			.error(function(data) { $.sendMsg('error'); });
		var serialData = 'cat=work&type=status';
		$.get('/manage/rows/pman-settings-rows.php', serialData)
			.success(function(data) { 
				$('#holder-work-statuss-rows').html(data);
			})
			.error(function(data) { $.sendMsg('error'); });
	} else {
		// EXCEPTIONS BEFORE .GET
		if (list==='jobs-rows') {
			if (setSTATUS==='EMPTY') { $('#filter-select-sort').val('job.dsc'); }
			if (setSEARCH.length>3) { $('#filter-select-status').val('ALL'); setSTATUS = 'ALL'; }
		}
		// GET INFO
		var serialData =	'cat='+setTYPE+
						'&client='+setCLIENT+
						'&in='+setIN+
						'&parent='+parentID+
						'&search='+setSEARCH+
						'&sort='+setSORT+
						'&status='+setSTATUS+
						'&type='+filter;
		$.get('/manage/rows/'+list+'.php', serialData)
			.success(function(data) { 
				$('#holder-'+list).html(data);
				// EXCEPTIONS ON SUCCESS
				if (list==='web-pages-rows' || list==='web-navigation-rows') {
					if (setCLIENT!=='ALL' || setSTATUS!=='ALL' || setSORT!=='ord' || setIN!=='ASC' || setSEARCH!=='') { $('.moving').hide(); } 
					else { $('.moving').show(); }
				} else if (list==='inventory-ordering-rows') {
					$('.check-box').click( function() {
						var thisID = $(this).attr('alt');
						if ($(this).prop('checked') === true) {
							$('.check-in[alt="'+thisID+'"]').focus();
						} else {
							$('.check-in[alt="'+thisID+'"]').val('');
						}
					});
					$('.check-in').on('click, change', function() {
						$('.check-in').each(function(index) {
							var thisID = $(this).attr('alt');
							var thisVal = $(this).val();
							var thisNum = $.isNumeric(thisVal);
							if (thisVal < 1){
								$('.check-box[alt="'+thisID+'"]').prop('checked', false);
							} else {
								$('.check-box[alt="'+thisID+'"]').prop('checked', true);
							}
							if (thisNum === false){
								$(this).css('color', 'red');
								$('.check-box[alt="'+thisID+'"]').prop('checked', false);
							} else {
								$(this).css('color', '#575757');
							}
						});
					});
				} else if (list==='lines-rows') {
					var serialData = 'a=2&i='+parentID+'&t=1&v=1&c=1';
					$.post('/manage/forms/update.php', serialData)
						.success(function(data) { 
							$('#inv_total').html('$'+data);
						})
						.error(function(data) { $.sendMsg('error'); });
				}
			})
			.error(function(data) { $.sendMsg('error'); });
	}
	
	
	$('.update-list').change( function(e){ 
		e.preventDefault(); 
		$.updatePageData(list, filter);
	});
	$('#button-search').click(function(e){
		e.preventDefault();
		$.updatePageData(list, filter);
	});
	$('.body').keyup( function (e){
		<?php if ($contents!='edit-web-page') { ?>
		if (e.keyCode === 13) { // RETURN
			e.preventDefault(); 
			$.updatePageData(list, filter);
		}
		<?php } ?>
		if (e.keyCode === 27) { // ESCAPE
			e.preventDefault(); 
			$.resetDefaults(list, filter);
		}
	});
	$('#button-reset').click(function(e){
		e.preventDefault();
		$.resetDefaults(list, filter);
	});
};
$.modalSafeTasks = function(taskID, projID, taskTYPE){
	if (taskID==='new') { var setTITLE = 'New Task'; } else { var setTITLE = 'Edit Task'; }
	var projStatus = $('#proj_status').val();
	if ((projStatus==='killed' || projStatus==='complete' || projStatus==='archive') && taskID==='new') {
		$.sendMsg('Error.', 'You cannot add a task to an inactive project.');
	} else {
		var serialData = 'id='+taskID+'&parent='+projID;
		$.get('/manage/forms/'+taskTYPE+'task-edit.php', serialData)
			.success(function(data) { 
				$('#dialog-edit-task').html(data);
				$('#dialog-edit-task').dialog({
					title: setTITLE,
					height: 'auto',
					width: 600,
					modal: false,
					buttons: {
						'OK': function() {
							var serialData = $('#form-edit-'+taskTYPE+'task').serialize()+'&id='+taskID+'&parent='+projID;
							$.post('/manage/forms/'+taskTYPE+'task-edit.php', serialData)
								.success(function(data) {
									if (typeof($('#proj_id').val())==='undefined') { $.updatePageData('tasks-rows', 'job'); }
									else { $.updatePageData('tasks-rows', 'proj'); }
									$.updatePageData('tasks-stickies');
									$.updatePageData('work-tasks-rows', 'work');
								})
								.error(function(data) { $.sendMsg('error'); });
							$( this ).dialog( 'close' );
						},
						'Cancel': function() {
							$( this ).dialog( 'close' );
						}
					}
				}).on('click', '.date', function(e){
					$(this).datepicker({ 
						showOn:'focus',
						dateFormat: 'yy-mm-dd',
						gotoCurrent: true
					}).focus();
				});
			})
			.error(function(data) { $.sendMsg('error'); });
	}
};

// DOCUMENT READY
$(function() {
	$.ajaxSetup({cache: false})
// MATCH HEIGHT AND WIDTH
	var maxWidth = 0;
	var maxHeight = 0;
	$('.match-h > span').each( function() {
		if ($(this).width() > maxWidth) {
			maxWidth = $(this).width();
		}
	}).css('width', maxWidth);
	$('.match-v > span').each( function() {
		if ($(this).height() > maxHeight) {
			maxHeight = $(this).height();
		}
	}).css('height', maxHeight);
// LOADING ICON
	$('body').on({
	    ajaxStart: function() { 
		   $(this).addClass('loading'); 
	    },
	    ajaxStop: function() { 
		   $(this).removeClass('loading'); 
	    }    
	});
// LIVE CLICKS
	$(document)
	// DATE PICKERS
	.on('click', '.date', function(e){
		$(this).datepicker({ 
			showOn:'focus',
			dateFormat: 'yy-mm-dd',
			gotoCurrent: true
		}).focus();
	})
	.on('click', '.dateNaked', function(e){
		$(this).datepicker({ 
			showOn:'focus',
			dateFormat: 'yymmdd',
			gotoCurrent: true
		}).focus();
	})
	.on('click', '.datetime', function(e){
		$(this).datetimepicker({ 
			showOn:'focus',
			dateFormat: 'DD, M. d, yy,',
			timeFormat: 'h:mm tt',
			gotoCurrent: true
		}).focus();
	})
	// NOTE EDIT
	.on('click', '.button-edit-note', function(e){
		e.preventDefault();
		var noteID = $(this).attr('rel');
		var noteTYPE = $(this).attr('name');
		if (noteID==='new') { var setTITLE = 'New Note'; } else { var setTITLE = 'Edit Note'; }
		var jobID = $('#'+noteTYPE+'_id').val();
		var serialData = 'id='+noteID+'&parent='+jobID+'&type='+noteTYPE;
		$.get('/manage/forms/note-edit.php', serialData)
			.success(function(data) { 
				$('#dialog-edit-note').html(data);
				$('#dialog-edit-note').dialog({
					title: setTITLE,
					height: 'auto',
					width: 450,
					modal: false,
					buttons: {
						'OK': function() {
							var serialData = $('#form-edit-note').serialize()+'&id='+noteID+'&parent='+jobID+'&type='+noteTYPE;
							$.post('/manage/forms/note-edit.php', serialData)
								.success(function(data) { 
									$('#dialog-edit-note').dialog('close');
									$.updatePageData('notes-rows', noteTYPE);
								})
								.error(function(data) { $.sendMsg('error'); });
						},
						'Cancel': function() {
							$(this).dialog('close');
						}
					}
				});
			})
			.error(function(data) { $.sendMsg('error'); });
	})
	// DATE PICKERS THAT AUTO-SUBMIT
	.on('click', '.button-edit-task-due, .button-edit-proj-due, .button-edit-todo-due, .button-edit-work-due, .button-edit-wask-due', function(e){
		e.preventDefault();
		if ($(this).hasClass('button-edit-task-due')) { var setTYPE = 'pman_tasks'; } 
		else if ($(this).hasClass('button-edit-todo-due')) { var setTYPE = 'pman_todos'; } 
		else if ($(this).hasClass('button-edit-work-due')) { var setTYPE = 'work_proj'; } 
		else if ($(this).hasClass('button-edit-wask-due')) { var setTYPE = 'work_task'; } 
		else { var setTYPE = 'pman_projects'; } 
		var itemID = $(this).attr('title');
		var itemDATE = $(this).attr('alt');
		$(this)
		.datepicker({ 
			onSelect: function(date) {
				var serialData = 'i='+itemID+'&t='+setTYPE+'&c=due&v='+date+'&a=1';
				$.post('/manage/forms/update.php', serialData)
					.success(function(data) { 
						$.sendMsg('Thank you.', 'The due date was updated successfully.');
						if (setTYPE === 'pman_projects') {
							if (typeof($('#proj_id').val())==='undefined') { $.updatePageData('tasks-rows', 'job'); } // project edit page?
							else { $.updatePageData('tasks-rows', 'proj'); }
						} 
						else if (setTYPE === 'pman_tasks') { $.updatePageData('tasks-stickies'); }
						else if (setTYPE === 'work_proj') { $.updatePageData('work-tasks-rows'); }
						else { $.updatePageData('checklist-stickies'); }
					})
					.error(function(data) { $.sendMsg('error'); });
			},
			showOn:'focus',
			dateFormat: 'yy-mm-dd',
			gotoCurrent: true
		})
		.datepicker('setDate', itemDATE)
		.focus();
	})
	// TEAM/OWNER EDIT
	.on('click', '.input-edit-job-team, .input-edit-proj-team, .input-edit-task-team, .input-edit-mcab-team, .input-edit-work-team', function(e){
		e.preventDefault();
		var itemID = $(this).attr('title');
		var itemTEAM = $(this).attr('alt');
		if (itemID==='new') { var setTITLE = 'New Team'; } else { var setTITLE = 'Edit Team'; }
		if ($(this).hasClass('input-edit-task-team')) { var setTYPE = 'task'; } 
		else if ($(this).hasClass('input-edit-proj-team')) { var setTYPE = 'proj'; } 
		else if ($(this).hasClass('input-edit-mcab-team')) { var setTYPE = 'mcab'; } 
		else if ($(this).hasClass('input-edit-work-team')) { var setTYPE = 'work'; } 
		else { var setTYPE = 'job'; }
		var serialData = 'id='+itemID+'&team='+itemTEAM+'&type='+setTYPE;
		$.get('/manage/forms/team-edit.php', serialData)
			.success(function(data) { 
				$('#dialog-edit-team').html(data);
				$('#dialog-edit-team').dialog({
					title: setTITLE,
					height: 'auto',
					width: 120,
					modal: false,
					buttons: {
						'Done': function() {
							if ($('.input-edit-'+setTYPE+'-team[title="'+itemID+'"]').is('a')) {
								var serialData = $('#form-edit-team').serialize()+'&id='+itemID+'&team='+itemTEAM+'&type='+setTYPE;
								$.post('/manage/forms/team-edit.php', serialData)
									.success(function(data) { 
										$('.input-edit-'+setTYPE+'-team[title="'+itemID+'"]').val(data);
										$.updatePageData('tasks-stickies');
										$.sendMsg('Thank you.', 'This '+setTYPE+' was updated successfully.');
									})
									.error(function(data) { $.sendMsg('error'); });
								$( this ).dialog( 'close' );
								if (typeof($('#proj_id').val())==='undefined') { $.updatePageData('tasks-rows', 'job'); $.updatePageData('jobs-rows'); } // project edit page?
								else { $.updatePageData('tasks-rows', 'proj'); }
							} else if ($('.input-edit-'+setTYPE+'-team[title="'+itemID+'"]').is('input')) {
								var sndBack = '';
								$('.team-check').each( function() {
									if ($(this).is(':checked')) {
										sndBack = $(this).attr('title')+' '+sndBack;
									}
								});
								$('.input-edit-'+setTYPE+'-team[title="'+itemID+'"]').val(sndBack);
								$( this ).dialog( 'close' );
							}
						},
						'Cancel': function() {
							$( this ).dialog( 'close' );
						}
					}
				});
			})
			.error(function(data) { $.sendMsg('error'); });
	});
// BODY AJAX CLICKS
	$(document) //'.body'
	// TASK EDIT
	.on('click', '.button-edit-task, .button-edit-wask', function(e){
		e.preventDefault();
		if ($(this).hasClass('button-edit-wask')) { var taskTYPE = 'work-'; }
		else { var taskTYPE = ''; }
		var taskID = $(this).attr('rel');
		var projID = $(this).attr('name');
		$.modalSafeTasks(taskID, projID, taskTYPE);
	})
	// TASK PREVIEWS
	.on('click', '.icon-box.task', function(e){
		e.preventDefault();
		var projID = $(this).attr('rel');
		var serialData = 'parent='+projID+'&type=proj';
		$.get('/manage/rows/tasks-rows.php', serialData)
			.success(function(data) { 
				$('#dialog-edit-task').html(data);
				$('#dialog-edit-task .button-edit-task[rel="new"]').remove();
				$('#dialog-edit-task').dialog({
					title: 'Click to edit a task',
					height: 'auto',
					width: 'auto',
					dialog: true
				});
				$('.button-edit-task').click(function(e){
					e.preventDefault();
					var taskID = $(this).attr('rel');
					var projID = $(this).attr('name');
					$.modalSafeTasks(taskID, projID);
				})
			})
			.error(function(data) { $.sendMsg('error'); });
	})
	// SHOW DETAILS
	.on('click', '.button-show-details', function(e){
		e.preventDefault();
		var setTITLE = $('#dialog-show-details').attr('rel');
		$('#dialog-show-details').dialog({
			title: setTITLE,
			height: 'auto',
			width: 'auto',
			dialog: true
		});
	})
	// NOTE PREVIEWS
	.on('click', '.icon-box.proj-note, .icon-box.task-note, .icon-box.todo-note, .icon-box.filter-note, .icon-box.work-note', function(e){
		e.preventDefault();
		var projID = $(this).attr('rel');
		if ($(this).hasClass('task-note')) { var setTYPE = 'task'; } 
		else if ($(this).hasClass('todo-note')) { var setTYPE = 'todo'; } 
		else if ($(this).hasClass('filter-note')) { var setTYPE = 'filter'; } 
		else if ($(this).hasClass('work-note')) { var setTYPE = 'work'; } 
		else { var setTYPE = 'proj'; } 
		var serialData = 'parent='+projID+'&type='+setTYPE;
		$.get('/manage/rows/notes-rows.php', serialData)
			.success(function(data) { 
				$('#dialog-edit-note').html(data);
				$('#dialog-edit-note .button-edit-note[rel="new"]').remove();
				$('#dialog-edit-note').dialog({
					title: '',
					height: 'auto',
					width: 'auto',
					dialog: true
				});
			})
			.error(function(data) { $.sendMsg('error'); });
	})
	// UPDATE LOG
	.on('click', '.dialog-view-log', function(e){
		e.preventDefault();
		var itemID = $(this).attr('rel');
		var itemTYPE = $(this).attr('name');
		var serialData = 'parent='+itemID+'&type='+itemTYPE;
		$.get('/manage/rows/updates-rows.php', serialData)
			.success(function(data) { 
				$('#dialog-view-log').html(data);
				$('#dialog-view-log').dialog({
					title: '',
					height: 'auto',
					width: 'auto',
					dialog: true
				});
			})
			.error(function(data) { $.sendMsg('error'); });
	})
	// MOVE STUFF 
	.on('click', '.button-move', function(e){
		e.preventDefault();
		var itemID = $(this).attr('rel');
		var itemCURR = $(this).attr('title');
		
		     if ($(this).hasClass('dir-up')) 	{ var itemMOVE = 'U'; var col = '1';	var val = '1'; } 
		else if ($(this).hasClass('dir-down')) 	{ var itemMOVE = 'D'; var col = '1';	var val = '1'; }
		else if ($(this).hasClass('dir-next')) 	{ var itemMOVE = 'N'; var col = 'tier'; var val = itemCURR; }
		else if ($(this).hasClass('dir-prev')) 	{ var itemMOVE = 'P'; var col = 'tier'; var val = itemCURR; }
		
			if ($(this).hasClass('this-work-pri')) 			{ var tab = 'pman_settings';			var ilist = 'work-edit-rows';				var itype = ''; }
		else if ($(this).hasClass('this-work-status'))		{ var tab = 'pman_settings';			var ilist = 'work-edit-rows';				var itype = ''; }
		else if ($(this).hasClass('this-work-cat'))			{ var tab = 'pman_settings';			var ilist = 'work-edit-rows';				var itype = ''; }
		else if ($(this).hasClass('this-work-client'))		{ var tab = 'pman_settings';			var ilist = 'work-edit-rows';				var itype = ''; }
		else if ($(this).hasClass('this-todo-lane'))			{ var tab = 'pman_settings';			var ilist = 'checklist-edit';				var itype = ''; } 
		else if ($(this).hasClass('this-todo-label'))		{ var tab = 'pman_settings';			var ilist = 'checklist-edit';				var itype = ''; } 
		else if ($(this).hasClass('this-web-survey-question'))	{ var tab = 'site_survey_questions';	var ilist = 'web-survey-questions-rows';	var itype = 'survey'; } 
		else if ($(this).hasClass('this-web-form-question'))	{ var tab = 'site_form_questions';		var ilist = 'web-form-questions-rows';		var itype = 'form'; } 
		else if ($(this).hasClass('this-web-page'))			{ var tab = 'site_page';				var ilist = 'web-pages-rows';				var itype = ''; } 
		else if ($(this).hasClass('this-web-nav'))			{ var tab = 'site_nav';				var ilist = 'web-navigation-rows';			var itype = ''; } 

		$.quickUpdate(tab, col, val, itemID, itemMOVE, ilist, itype);
	})
	// EDIT DIALOGS
	.on('click', '.button-edit-item', function(e){
		e.preventDefault();
		
			if ($(this).hasClass('this-line')) 				{ var itemTYPE = 'line';					var parentTYPE = 'cost'; }
		else if ($(this).hasClass('this-web-redirect'))			{ var itemTYPE = 'web-redirect';			var parentTYPE = ''; }
		else if ($(this).hasClass('this-show-date'))				{ var itemTYPE = 'show-date';				var parentTYPE = 'show'; }
		else if ($(this).hasClass('this-web-survey-question'))		{ var itemTYPE = 'web-survey-question';		var parentTYPE = 'survey'; }
		else if ($(this).hasClass('this-web-survey-option'))		{ var itemTYPE = 'web-survey-option';		var parentTYPE = 'survey'; }
		else if ($(this).hasClass('this-web-form-question'))		{ var itemTYPE = 'web-form-question';		var parentTYPE = 'form'; }
		else if ($(this).hasClass('this-web-form-option'))		{ var itemTYPE = 'web-form-option';		var parentTYPE = 'form'; }
		else if ($(this).hasClass('this-web-traffic-filter'))		{ var itemTYPE = 'web-traffic-filter';		var parentTYPE = ''; }
		else if ($(this).hasClass('this-login'))				{ var itemTYPE = 'login';				var parentTYPE = ''; }
		else if ($(this).hasClass('this-todo-lane'))				{ var itemTYPE = 'todo-lane';				var parentTYPE = ''; }
		else if ($(this).hasClass('this-todo-label'))			{ var itemTYPE = 'todo-label';			var parentTYPE = ''; }
		else if ($(this).hasClass('this-checklist'))				{ var itemTYPE = 'checklist';				var parentTYPE = ''; }
		else if ($(this).hasClass('this-inventory-order'))		{ var itemTYPE = 'inventory-order';		var parentTYPE = 'mcab'; }
		else if ($(this).hasClass('this-work-pri'))				{ var itemTYPE = 'work-pri';				var parentTYPE = ''; }
		else if ($(this).hasClass('this-work-status'))			{ var itemTYPE = 'work-status';			var parentTYPE = ''; }
		else if ($(this).hasClass('this-work-cat'))				{ var itemTYPE = 'work-cat';				var parentTYPE = ''; }
		else if ($(this).hasClass('this-work-client'))			{ var itemTYPE = 'work-client';			var parentTYPE = ''; }
		else { $.sendMsg('error'); }
		
		var itemID = $(this).attr('rel');
		var itemOLD = $(this).attr('alt');
		if ($(this).hasClass('complete')) { var itemSTATUS = 'yes'; } else { var itemSTATUS = 'no'; }
		var parentTHIS = '#'+parentTYPE+'_id';
		var parentID = $(parentTHIS).val();
		if ($(this).attr('name')>0) { var parentID = $(this).attr('name'); }

		if (itemID==='new') { var setTITLE = 'New'; } else { var setTITLE = 'Edit'; }
		var serialData = 'id='+itemID+'&parent='+parentID+'&old='+itemOLD+'&approved='+itemSTATUS;
		$.get('/manage/forms/'+itemTYPE+'-edit.php', serialData)
			.success(function(data) { 
				$('#dialog-edit-'+itemTYPE).html(data);
				$('#dialog-edit-'+itemTYPE).dialog({
					title: setTITLE,
					height: 'auto',
					width: 550,
					modal: false,
					buttons: {
						'OK': function() {
							var serialData = $('#form-edit-'+itemTYPE).serialize()+'&id='+itemID+'&parent='+parentID+'&old='+itemOLD+'&approved='+itemSTATUS;
							$.post('/manage/forms/'+itemTYPE+'-edit.php', serialData)
								.success(function(data) { 
									$('#dialog-edit-'+itemTYPE).dialog('close');
									if (itemTYPE === 'checklist') { $.updatePageData('checklist-stickies'); } 
									else if (itemTYPE === 'todo-lane' || itemTYPE === 'todo-label') { $.updatePageData('checklist-edit'); } 
									else if (itemTYPE === 'web-survey-option') { $.updatePageData('web-survey-questions-rows', parentTYPE); } 
									else if (itemTYPE === 'web-form-option') { $.updatePageData('web-form-questions-rows', parentTYPE); } 
									else if (itemTYPE === 'inventory-order') { document.location.href='/manage/edit-inventory/'+parentID } 
									else if (
										itemTYPE === 'work-cat' ||
										itemTYPE === 'work-client' ||
										itemTYPE === 'work-pri' ||
										itemTYPE === 'work-status'
									) { $.updatePageData('work-edit-rows'); } 
									else { $.updatePageData(itemTYPE+'s-rows', parentTYPE); }
								})
								.error(function(data) { $.sendMsg('error'); });
						},
						'Cancel': function() {
							$(this).dialog('close');
						}
					}
				}).on('click', '.date', function(e){
					$(this).datepicker({ 
						showOn:'focus',
						dateFormat: 'yy-mm-dd',
						gotoCurrent: true
					}).focus();
				});
				if (itemTYPE === 'line') {
					$('.line-amt, .line-price, .line-total').on('change', function() {
						var amt = $('.line-amt').val();
						var pri = $('.line-price').val();
						var tot = amt * pri;
						$('.line-total').val(tot);
					});
				}
			})
			.error(function(data) { $.sendMsg('error'); });
	});
// NOTIFICATIONS
	$('.notify-accepted').click( function(e){
		e.preventDefault();
		var itemID = $(this).attr('rel');
		var serialData = 'i='+itemID+'&t=log_notify&c=status&v=accepted&a=1';
		$.post('/manage/forms/update.php', serialData)
			.success(function(data) { 
				countNotify--;
				$('#notify-on').text(countNotify);
				$('.notify-accepted[rel="'+itemID+'"]').closest('p').remove();
			})
			.error(function(data) { $.sendMsg('error'); });
	});
// DRAG AND DROP LANES 
	<?php if (($contents=='checklist' || $contents=='tasks') && $mobility=='desktop') { ?>
		$('#trello').on('hover', '.drag-it', function () {
			$(this).draggable({ revert: 'invalid' });
			var itemID = $(this).attr('id');
			if ($(this).hasClass('task')) { var thisTYPE = 'task'; var thisSTATUS = 'complete'; }
			else if ($(this).hasClass('todo')) { var thisTYPE = 'todo'; var thisSTATUS = '<?php echo $final_status_id; ?>'; }
			<?php 
			pg_result_seek($result, 0);
			while ($lane = pg_fetch_array($result)) { ?>
				$('.drop-it.<?php echo $lane['alt']; ?>').droppable({
					greedy: true,
					hoverClass: 'drop-hover',
					drop: function( event, ui ) {
						var serialData = 'i='+itemID+'&t=pman_'+thisTYPE+'s&c=status&v=<?php echo $lane['id']; ?>&a=1';
						$.post('/manage/forms/update.php', serialData)
							.error(function(data) { $.sendMsg('error'); });
						if (thisTYPE==='todo') { $.updatePageData('checklist-stickies'); }
						else if (thisTYPE==='task') { $.updatePageData('tasks-stickies'); }
					}
				});<?php 
			} ?>
			$('.trash').droppable({
				greedy: true,
				hoverClass: 'drop-hover',
				drop: function( event, ui ) {
					var serialData = 'i='+itemID+'&t=pman_'+thisTYPE+'s&c=status&v='+thisSTATUS+'&a=1';
					$.post('/manage/forms/update.php', serialData)
						.error(function(data) { $.sendMsg('error'); });
					if (thisTYPE==='todo') { $.updatePageData('checklist-stickies'); }
					else if (thisTYPE==='task') { $.updatePageData('tasks-stickies'); }
				}
			});
		});
	<?php } ?>
// BUTTONS
	$(document).keydown(function(event) {
		if (!( String.fromCharCode(event.which).toLowerCase() == 's' && event.metaKey) && !(event.which == 19)) return true;
		$('.auto-save').trigger('click');
		event.preventDefault();
		return false;
	}).keydown(function(event) {
		if (!( String.fromCharCode(event.which).toLowerCase() == 's' && event.ctrlKey) && !(event.which == 19)) return true;
		$('.auto-save').trigger('click');
		event.preventDefault();
		return false;
	});
	$('#button-toggle-lanes').click(function(e){
		e.preventDefault();
		$('#trello #killed, #trello #complete').toggle();
	});
	$('#button-save-main-form').click( function(e){
		e.preventDefault();
		var sch = $(this).attr('title');
		var frm = $(this).attr('name');
		var req1 = $('#req1').val();
		var err1 = $('#req1').attr('alt');
		var req2 = $('#req2').val();
		var err2 = $('#req2').attr('alt');
		if ($('#'+sch+'_id').val() === '') { alert('ID!'); }
		else {
			if ($('#'+sch+'_'+req1).val() === '' && req1!=='') {
				$.sendMsg('Not enough information.', 'You must enter '+err1+'.');		
			} else if ($('#'+sch+'_'+req2).val() === '' && req2!=='') {
				$.sendMsg('Not enough information.', 'You must enter '+err2+'.');		
			} else {
				var serialData = $('#form-edit-'+frm).serialize();
				$.post('/manage/forms/'+frm+'-edit.php', serialData)
					.success(function(data) { 
						if ($('#'+sch+'_id').val() === 'new') { document.location.href='/manage/edit-'+frm+'/'+data; }
						else {
							$.sendMsg('Thank you.', 'Updated successfully.');
							$.updatePageData('tasks-rows', sch);
							$.updatePageData('notes-rows', sch);
							$.updatePageData('costs-rows', sch);
							$.updatePageData('links-rows', sch);
						}
					})
					.error(function(data) { $.sendMsg('error'); });
			}
		}
	});
}); // DOC READY
</script>
Back to Top