-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.php
More file actions
1091 lines (998 loc) · 52 KB
/
admin.php
File metadata and controls
1091 lines (998 loc) · 52 KB
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
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
session_start();
// Default credentials
$valid_username = 'admin';
$valid_password = 'pass';
// Handle logout
if (isset($_GET['logout'])) {
session_destroy();
header('Location: ' . strtok($_SERVER['REQUEST_URI'], '?'));
exit;
}
// Handle login
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['login'])) {
if ($_POST['username'] === $valid_username && $_POST['password'] === $valid_password) {
$_SESSION['logged_in'] = true;
header('Location: ' . strtok($_SERVER['REQUEST_URI'], '?'));
exit;
} else {
$login_error = 'Invalid credentials';
}
}
// Handle save configuration
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['save_config']) && isset($_SESSION['logged_in'])) {
$config = [
'sections' => json_decode($_POST['sections'], true),
'platforms' => json_decode($_POST['platforms'], true),
'features' => json_decode($_POST['features'], true),
'extras' => json_decode($_POST['extras'], true),
'timeframes' => json_decode($_POST['timeframes'], true)
];
// Save config to file
file_put_contents('brief_config.json', json_encode($config, JSON_PRETTY_PRINT));
// Generate the new HTML file
$html_content = generateHtmlFromConfig($config);
file_put_contents('generated_brief.html', $html_content);
$save_success = 'Configuration saved and HTML generated successfully!';
}
function generateHtmlFromConfig($config) {
$platforms_html = '';
foreach ($config['platforms'] as $platform) {
$platforms_html .= sprintf(
'<label><input type="checkbox" value="%s" data-cost="%s" class="platform-check"> %s</label>',
htmlspecialchars($platform['value']),
htmlspecialchars($platform['cost']),
htmlspecialchars($platform['label'])
);
}
$features_html = '';
foreach ($config['features'] as $feature) {
$features_html .= sprintf(
'<label><input type="checkbox" value="%s" data-cost="%s"> %s</label>',
htmlspecialchars($feature['value']),
htmlspecialchars($feature['cost']),
htmlspecialchars($feature['label'])
);
}
$extras_html = '';
foreach ($config['extras'] as $extra) {
$extras_html .= sprintf(
'<label><input type="checkbox" value="%s" data-cost="%s"> %s</label>',
htmlspecialchars($extra['value']),
htmlspecialchars($extra['cost']),
htmlspecialchars($extra['label'])
);
}
// Timeframes logic
$timeframes_js = json_encode($config['timeframes']);
return <<<HTML
<!--
Project Brief Questionnaire
Copyright (c) ColeNikol 2026
This application is released under the MIT License.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files to deal in the Software
without restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
---------------------------------------------------------------------
Third-party libraries used in this application:
Tailwind CSS
https://tailwindcss.com
License: MIT License
Font Awesome Free
https://fontawesome.com
Icons License: CC BY 4.0
Fonts License: SIL Open Font License 1.1
Code License: MIT License
html2canvas
https://html2canvas.hertzen.com
License: MIT License
jsPDF
https://github.com/parallax/jsPDF
License: MIT License
All third-party libraries are used via public CDN and remain the property
of their respective authors.
---------------------------------------------------------------------
App stack:
- Responsive HTML5
- Tailwind CSS (CDN)
- Font Awesome Free icons
- Vanilla JavaScript
- html2canvas for DOM capture
- jsPDF for PDF generation
---------------------------------------------------------------------
App name: Project Brief Questionnaire
App version: 1.0.1
Author: ColeNikol aka ColeN / https://bit.ly/colenikol
License: MIT
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Project Brief Questionnaire</title>
<!-- Tailwind + Font Awesome -->
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
<!-- html2canvas + jsPDF -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
<style>
/* ensure all inputs have placeholders, and pdf will render them as static text via cloning */
input, textarea {
line-height: 1.5 !important;
padding: 0.75rem !important;
white-space: normal !important;
word-wrap: break-word !important;
overflow-wrap: break-word !important;
height: auto !important;
min-height: 3rem;
box-sizing: border-box !important;
background-color: white;
}
textarea {
min-height: 6rem;
resize: vertical;
}
/* grid for checkboxes with consistent alignment */
.checkbox-grid {
display: flex;
flex-wrap: wrap;
gap: 0.75rem 1.5rem;
align-items: center;
}
.checkbox-grid label {
display: inline-flex;
align-items: center;
gap: 0.4rem;
white-space: nowrap;
}
/* image grid - preserve original aspect */
.image-grid-img {
width: 100%;
height: auto;
object-fit: contain;
background-color: #f8fafc;
border-radius: 0.5rem;
border: 1px solid #e2e8f0;
display: block;
}
.image-item {
transition: all 0.15s;
position: relative;
display: flex;
justify-content: center;
background: #f1f5f9;
border-radius: 0.5rem;
}
.remove-image-btn {
opacity: 0;
transition: opacity 0.15s;
position: absolute;
top: -0.5rem;
right: -0.5rem;
background-color: #ef4444;
color: white;
border-radius: 9999px;
width: 2rem;
height: 2rem;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
border: 2px solid white;
cursor: pointer;
z-index: 10;
}
.image-item:hover .remove-image-btn {
opacity: 1;
}
.spinner {
border: 2px solid #f1f5f9;
border-top: 2px solid #3b82f6;
border-radius: 50%;
width: 1.2rem;
height: 1.2rem;
animation: spin 0.7s linear infinite;
display: inline-block;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
/* color picker row */
.palette-row {
display: flex;
flex-wrap: wrap;
gap: 1rem;
align-items: center;
background: #f8fafc;
padding: 1rem;
border-radius: 1rem;
border: 1px solid #e2e8f0;
}
.color-palette-item {
display: flex;
flex-direction: column;
align-items: center;
background: white;
padding: 0.5rem;
border-radius: 0.75rem;
box-shadow: 0 1px 3px rgba(0,0,0,0.05);
min-width: 100px;
border: 1px solid #e9eef2;
}
.color-swatch-large {
width: 3rem;
height: 3rem;
border-radius: 0.5rem;
border: 2px solid #e2e8f0;
margin-bottom: 0.25rem;
cursor: pointer;
}
.color-hex-display {
font-size: 0.7rem;
background: #f1f5f9;
padding: 0.2rem;
border-radius: 0.25rem;
margin-top: 0.2rem;
width: 100%;
text-align: center;
}
.remove-color-btn {
margin-top: 0.25rem;
font-size: 0.7rem;
color: #ef4444;
background: none;
border: none;
cursor: pointer;
}
</style>
</head>
<body class="bg-slate-50 font-sans antialiased p-4 md:p-6">
<div class="max-w-6xl mx-auto">
<!-- capture area (everything except buttons) -->
<div id="pdfCaptureArea" class="bg-white rounded-2xl shadow-xl border border-slate-200 overflow-hidden">
<div class="h-1 bg-transparent"></div>
<div class="p-6 md:p-8 space-y-8">
<!-- header -->
<h1 class="text-3xl md:text-4xl font-bold text-slate-800 flex items-center gap-3">
<i class="fa-solid fa-pen-ruler text-blue-600"></i>
<span>Project Brief Questionnaire</span>
</h1>
<!-- ===== CLIENT ===== -->
<section>
<h2 class="text-lg font-semibold text-slate-700 mb-3 flex items-center gap-2 border-b border-slate-100 pb-2"><i class="fa-regular fa-address-card text-blue-400"></i> Client info</h2>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
<input id="fullName" type="text" required placeholder="Name (required)" class="w-full border border-slate-200 rounded-lg bg-white">
<input id="email" type="email" required placeholder="Email (required)" class="w-full border border-slate-200 rounded-lg bg-white">
<input id="company" type="text" placeholder="Company (optional)" class="w-full border border-slate-200 rounded-lg bg-white">
<input id="phone" type="tel" placeholder="Phone (optional)" class="w-full border border-slate-200 rounded-lg bg-white">
</div>
</section>
<!-- ===== PROJECT ===== -->
<section>
<h2 class="text-lg font-semibold text-slate-700 mb-3 flex items-center gap-2 border-b border-slate-100 pb-2"><i class="fa-regular fa-file-lines text-blue-400"></i> Project details</h2>
<input id="projectName" type="text" placeholder="Project name (e.g. Your App Idea)" class="w-full border border-slate-200 rounded-lg mb-4 bg-white">
<textarea id="description" rows="3" placeholder="Describe the core idea, goals, target audience, and any must-have features..." class="w-full border border-slate-200 rounded-lg bg-white"></textarea>
</section>
<!-- ===== PLATFORMS ===== -->
<section>
<h2 class="text-lg font-semibold text-slate-700 mb-3 flex items-center gap-2 border-b border-slate-100 pb-2"><i class="fa-regular fa-window-maximize text-indigo-400"></i> target platforms</h2>
<div class="checkbox-grid">
{$platforms_html}
</div>
</section>
<!-- ===== FEATURES ===== -->
<section>
<h2 class="text-lg font-semibold text-slate-700 mb-3 flex items-center gap-2 border-b border-slate-100 pb-2"><i class="fa-regular fa-rectangle-list text-blue-400"></i> Features & modules</h2>
<div class="checkbox-grid">
{$features_html}
</div>
<div class="mt-4">
<input id="customFeatures" type="text" placeholder="Additional custom features" class="w-full border border-slate-200 rounded-lg bg-white">
</div>
</section>
<!-- ===== EXTRAS ===== -->
<section>
<h2 class="text-lg font-semibold text-slate-700 mb-3 flex items-center gap-2 border-b border-slate-100 pb-2"><i class="fa-regular fa-gem text-blue-400"></i> Extras / Add-ons</h2>
<div class="checkbox-grid">
{$extras_html}
</div>
</section>
<!-- ===== THEME COLORS ===== -->
<section>
<h2 class="text-lg font-semibold text-slate-700 mb-3 flex items-center gap-2 border-b border-slate-100 pb-2"><i class="fa-solid fa-palette text-blue-400"></i> Colors palette</h2>
<div id="paletteRow" class="palette-row">
<!-- dynamic color items injected here -->
</div>
<button id="addColorBtn" type="button" class="mt-3 text-sm bg-indigo-50 hover:bg-indigo-100 text-blue-700 px-4 py-2 rounded-lg border border-indigo-200 inline-flex items-center gap-2"><i class="fa-regular fa-plus"></i> add color (max 5)</button>
</section>
<!-- ===== IMAGE MANAGER ===== -->
<section>
<h2 class="text-lg font-semibold text-slate-700 mb-3 flex items-center gap-2 border-b border-slate-100 pb-2"><i class="fa-regular fa-images text-blue-400"></i> Reference images</h2>
<div class="flex items-center gap-3">
<label for="imageUpload" class="cursor-pointer bg-indigo-50 hover:bg-indigo-100 text-blue-700 font-medium px-5 py-3 rounded-lg border border-indigo-200 inline-flex items-center gap-2 transition">
<i class="fa-regular fa-plus"></i> add images
</label>
<input type="file" id="imageUpload" multiple accept="image/*" class="hidden">
<span class="text-sm text-slate-400" id="imageCounter">0 images</span>
</div>
<div id="imageGrid" class="grid grid-cols-2 md:grid-cols-4 gap-4 mt-5"></div>
</section>
<!-- ===== NOTES ===== -->
<section>
<h2 class="text-lg font-semibold text-slate-700 mb-3 flex items-center gap-2 border-b border-slate-100 pb-2"><i class="fa-regular fa-note-sticky text-blue-400"></i> Additional notes / Timeline / Budget</h2>
<textarea id="notes" rows="3" placeholder="e.g. Q2 2026, budget $250-$1k, integrations with other apps, colors, sites for inspiration..." class="w-full border border-slate-200 rounded-lg bg-white"></textarea>
</section>
<!-- ===== ESTIMATE ===== -->
<section class="bg-slate-50 p-6 rounded-xl border border-slate-200">
<h2 class="text-lg font-bold text-slate-800 mb-4 flex items-center gap-2"><i class="fa-solid fa-chart-line text-green-600"></i> estimate snapshot</h2>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div><span class="text-sm text-slate-500">estimated price</span><div id="priceDisplay" class="text-3xl font-bold text-blue-700">$0</div></div>
<div><span class="text-sm text-slate-500">complexity</span><div id="complexityDisplay" class="text-2xl font-semibold">Low</div></div>
<div><span class="text-sm text-slate-500">timeframe</span><div id="timeDisplay" class="text-2xl font-semibold">1-2 weeks</div></div>
</div>
</section>
<div class="text-xs text-slate-300 text-right">* We'll get you back with correct offer once you send us the filled form PDF</div>
</div>
</div> <!-- end capture area -->
<!-- action button -->
<div class="mt-8 flex flex-wrap justify-end gap-4">
<button id="exportPdfBtn" class="px-8 py-3 bg-indigo-700 hover:bg-indigo-800 text-white rounded-xl shadow-md flex items-center gap-3 text-lg font-medium transition"><i class="fa-solid fa-file-arrow-down"></i> Export as PDF</button>
</div>
<p class="text-xs text-right text-slate-400 mt-3">Send us your Project Brief <a href="https://sites.google.com/view/stojan-nikolovski/contact">via DM</a></p>
</div>
<script>
(function() {
// DOM elements
const fullName = document.getElementById('fullName');
const email = document.getElementById('email');
const company = document.getElementById('company');
const phone = document.getElementById('phone');
const projectName = document.getElementById('projectName');
const description = document.getElementById('description');
const customFeatures = document.getElementById('customFeatures');
const notes = document.getElementById('notes');
const imageUpload = document.getElementById('imageUpload');
const imageGrid = document.getElementById('imageGrid');
const imageCounter = document.getElementById('imageCounter');
const exportBtn = document.getElementById('exportPdfBtn');
const captureArea = document.getElementById('pdfCaptureArea');
const addColorBtn = document.getElementById('addColorBtn');
const paletteRow = document.getElementById('paletteRow');
const priceDisplay = document.getElementById('priceDisplay');
const complexityDisplay = document.getElementById('complexityDisplay');
const timeDisplay = document.getElementById('timeDisplay');
const allCheckboxes = document.querySelectorAll('input[type=checkbox][data-cost]');
// Timeframes configuration
const timeframes = {$timeframes_js};
// ----- Color palette with HEX only -----
let colorItems = [
{ hex: '#303633' },
];
const MAX_COLORS = 5;
function renderPalette() {
let html = '';
colorItems.forEach((item, index) => {
html += `
<div class="color-palette-item" data-index="\${index}">
<div class="color-swatch-large" style="background-color: \${item.hex};"></div>
<div class="color-hex-display">\${item.hex}</div>
\${index > 0 ? `<button class="remove-color-btn" data-index="\${index}"><i class="fa-regular fa-trash-can"></i> remove</button>` : ''}
</div>
`;
});
paletteRow.innerHTML = html;
document.querySelectorAll('.color-swatch-large').forEach((swatch, idx) => {
swatch.addEventListener('click', function(e) {
const input = document.createElement('input');
input.type = 'color';
input.value = colorItems[idx].hex;
input.addEventListener('input', (e) => {
colorItems[idx].hex = e.target.value;
renderPalette();
});
input.click();
});
});
document.querySelectorAll('.remove-color-btn').forEach(btn => {
btn.addEventListener('click', (e) => {
const idx = btn.dataset.index;
colorItems.splice(idx, 1);
renderPalette();
addColorBtn.disabled = colorItems.length >= MAX_COLORS;
addColorBtn.classList.toggle('opacity-50', colorItems.length >= MAX_COLORS);
});
});
}
renderPalette();
addColorBtn.addEventListener('click', () => {
if (colorItems.length < MAX_COLORS) {
colorItems.push({ hex: '#aabbcc' });
renderPalette();
}
addColorBtn.disabled = colorItems.length >= MAX_COLORS;
addColorBtn.classList.toggle('opacity-50', colorItems.length >= MAX_COLORS);
});
// ----- image manager -----
let imageList = [];
function renderImageGrid() {
if (imageList.length === 0) {
imageGrid.innerHTML = `<div class="col-span-full text-slate-400 text-sm italic py-6 text-center border border-dashed rounded-lg">no images added</div>`;
} else {
let html = '';
imageList.forEach((img) => {
html += `
<div class="relative image-item">
<img src="\${img.dataURL}" class="image-grid-img" alt="ref" loading="lazy">
<button class="remove-image-btn" data-id="\${img.id}"><i class="fa-regular fa-times"></i></button>
</div>
`;
});
imageGrid.innerHTML = html;
document.querySelectorAll('.remove-image-btn').forEach(btn => {
btn.addEventListener('click', (e) => {
const id = btn.dataset.id;
imageList = imageList.filter(img => img.id != id);
renderImageGrid();
updateImageCounter();
});
});
}
updateImageCounter();
}
function updateImageCounter() {
imageCounter.innerText = imageList.length + ' image' + (imageList.length !== 1 ? 's' : '');
}
imageUpload.addEventListener('change', function(e) {
const files = Array.from(e.target.files);
files.forEach(file => {
if (!file.type.startsWith('image/')) return;
const reader = new FileReader();
reader.onload = (ev) => {
imageList.push({
dataURL: ev.target.result,
id: Date.now() + Math.random() + '-' + file.name
});
renderImageGrid();
};
reader.readAsDataURL(file);
});
imageUpload.value = '';
});
renderImageGrid();
// ----- estimate calculation with configurable timeframes -----
function calculateEstimate() {
let total = 0;
let count = 0;
allCheckboxes.forEach(cb => {
if (cb.checked) {
total += Number(cb.dataset.cost) || 0;
count++;
}
});
priceDisplay.innerText = '$' + total;
let complexity = 'Low';
let time = timeframes.low;
if (count > 4 && count <= 8) {
complexity = 'Medium';
time = timeframes.medium;
} else if (count > 8) {
complexity = 'High';
time = timeframes.high;
}
complexityDisplay.innerText = complexity;
timeDisplay.innerText = time;
}
allCheckboxes.forEach(cb => cb.addEventListener('change', calculateEstimate));
calculateEstimate();
// ----- PDF export: multi-page A4 with proper width, INCLUDING theme colors -----
exportBtn.addEventListener('click', async function() {
// Validate required fields
if (!fullName.value.trim() || !email.value.trim()) {
alert('Please fill in Name and Email fields before exporting.');
return;
}
const originalContent = exportBtn.innerHTML;
exportBtn.innerHTML = `<span class="spinner mr-2"></span> generating PDF...`;
exportBtn.disabled = true;
try {
await new Promise(resolve => setTimeout(resolve, 100));
// IMPORTANT: Do NOT hide the palette row - we want colors in the PDF
// We only hide the add button to keep it clean
const addBtn = addColorBtn;
const addBtnDisplay = addBtn.style.display;
addBtn.style.display = 'none';
// Create canvas from the entire capture area
const canvas = await html2canvas(captureArea, {
scale: 2,
backgroundColor: '#ffffff',
logging: false,
useCORS: true,
allowTaint: false,
windowWidth: captureArea.scrollWidth,
windowHeight: captureArea.scrollHeight,
onclone: (clonedDoc) => {
// Replace inputs with static text
const inputs = clonedDoc.querySelectorAll('input:not([type=checkbox]):not([type=color]), textarea');
inputs.forEach(el => {
const parent = el.parentNode;
const value = el.value || el.placeholder || '';
const staticDiv = clonedDoc.createElement('div');
staticDiv.className = 'border border-slate-200 rounded-lg bg-white p-3 min-h-[3rem]';
staticDiv.style.lineHeight = '1.5';
staticDiv.style.whiteSpace = 'pre-wrap';
staticDiv.style.wordWrap = 'break-word';
staticDiv.style.padding = '0.75rem';
staticDiv.textContent = value || ' ';
parent.replaceChild(staticDiv, el);
});
// Also hide the add button in the clone
const cloneAddBtn = clonedDoc.getElementById('addColorBtn');
if (cloneAddBtn) {
cloneAddBtn.style.display = 'none';
}
}
});
// Restore add button visibility
addBtn.style.display = addBtnDisplay;
// Create PDF with A4 dimensions
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({
orientation: 'portrait',
unit: 'mm',
format: 'a4'
});
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = pdf.internal.pageSize.getHeight();
// Calculate the scaling factor to fit the canvas width to A4 width
const scale = pdfWidth / canvas.width;
// Calculate the height of the content in PDF units
const contentHeight = canvas.height * scale;
// Calculate how many pages we need
const pageHeight = pdfHeight;
let remainingHeight = contentHeight;
let currentPosition = 0;
// Add first page
let pageIndex = 0;
while (remainingHeight > 0) {
if (pageIndex > 0) {
pdf.addPage();
}
// Calculate the portion of the canvas to render on this page
const sourceY = currentPosition / scale;
const pageCanvasHeight = Math.min(pageHeight / scale, canvas.height - sourceY);
// Create a canvas for this page
const pageCanvas = document.createElement('canvas');
pageCanvas.width = canvas.width;
pageCanvas.height = pageCanvasHeight;
const ctx = pageCanvas.getContext('2d');
ctx.drawImage(canvas, 0, sourceY, canvas.width, pageCanvasHeight, 0, 0, canvas.width, pageCanvasHeight);
// Add image to PDF
const pageImgData = pageCanvas.toDataURL('image/jpeg', 0.95);
pdf.addImage(pageImgData, 'JPEG', 0, 0, pdfWidth, pageCanvasHeight * scale, undefined, 'FAST');
remainingHeight -= pageHeight;
currentPosition += pageHeight;
pageIndex++;
}
pdf.save(`brief_\${projectName.value.trim() || 'project'}.pdf`);
} catch (error) {
console.error('PDF error', error);
alert('PDF generation failed. Please try again.');
} finally {
exportBtn.innerHTML = originalContent;
exportBtn.disabled = false;
}
});
})();
</script>
<noscript>JavaScript required.</noscript>
</body>
</html>
HTML;
}
// Default configuration based on the provided generated_brief.html
$default_config = [
'sections' => ['client', 'project', 'platforms', 'features', 'extras', 'colors', 'images', 'notes', 'estimate'],
'platforms' => [
['label' => 'Web', 'value' => 'Web', 'cost' => 1000],
['label' => 'Mobile', 'value' => 'Mobile', 'cost' => 2000],
['label' => 'Desktop', 'value' => 'Desktop', 'cost' => 1500],
['label' => 'Other', 'value' => 'Other', 'cost' => 3000]
],
'features' => [
['label' => 'Authentication', 'value' => 'Authentication', 'cost' => 15],
['label' => 'Dashboard', 'value' => 'Dashboard', 'cost' => 50],
['label' => 'User Profiles', 'value' => 'User Profiles', 'cost' => 100],
['label' => 'Payments', 'value' => 'Payments', 'cost' => 250],
['label' => 'Notifications', 'value' => 'Notifications', 'cost' => 50],
['label' => 'Admin Panel', 'value' => 'Admin Panel', 'cost' => 50],
['label' => 'API', 'value' => 'API', 'cost' => 250],
['label' => 'File Uploads', 'value' => 'File Uploads', 'cost' => 20],
['label' => 'Search', 'value' => 'Search', 'cost' => 20],
['label' => 'Real-time', 'value' => 'Real-time', 'cost' => 40],
['label' => 'Analytics', 'value' => 'Analytics', 'cost' => 20],
['label' => 'Export-Import', 'value' => 'Export-Import', 'cost' => 50]
],
'extras' => [
['label' => 'Logo creation', 'value' => 'Logo creation', 'cost' => 100],
['label' => 'Ads (common sizes)', 'value' => 'Ads (common sizes)', 'cost' => 75],
['label' => 'Landing page', 'value' => 'Landing page', 'cost' => 50],
['label' => 'SEO post', 'value' => 'SEO post', 'cost' => 20],
['label' => 'Video / explainer', 'value' => 'Video / explainer', 'cost' => 200],
['label' => 'Extra revisions', 'value' => 'Extra revisions', 'cost' => 20],
['label' => 'Social media kit', 'value' => 'Social media kit', 'cost' => 100],
['label' => 'Content writing', 'value' => 'Content writing', 'cost' => 20]
],
'timeframes' => [
'low' => '3 Days',
'medium' => '7 Days',
'high' => '2 Weeks'
]
];
// Load saved config if exists
$config = $default_config;
if (file_exists('brief_config.json')) {
$saved_config = json_decode(file_get_contents('brief_config.json'), true);
if ($saved_config) {
$config = array_merge($default_config, $saved_config);
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin · Project Brief Generator</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
<style>
.config-item {
background: #f8fafc;
border-radius: 0.5rem;
padding: 1rem;
border: 1px solid #e2e8f0;
}
.config-item-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1rem;
}
.item-row {
display: grid;
grid-template-columns: 1fr 100px 120px;
gap: 0.5rem;
margin-bottom: 0.5rem;
align-items: center;
}
.item-row input {
padding: 0.5rem;
border: 1px solid #e2e8f0;
border-radius: 0.375rem;
width: 100%;
}
.remove-btn {
color: #ef4444;
cursor: pointer;
background: none;
border: none;
font-size: 1.25rem;
}
.add-btn {
background: #3b82f6;
color: white;
padding: 0.5rem 1rem;
border-radius: 0.375rem;
border: none;
cursor: pointer;
font-size: 0.875rem;
}
.add-btn:hover {
background: #2563eb;
}
.nav-tabs {
display: flex;
gap: 1rem;
margin-bottom: 2rem;
border-bottom: 2px solid #e2e8f0;
padding-bottom: 0.5rem;
flex-wrap: wrap;
}
.nav-tab {
cursor: pointer;
padding: 0.5rem 1rem;
color: #64748b;
font-weight: 500;
border-radius: 0.375rem;
}
.nav-tab.active {
color: #3b82f6;
background: #eff6ff;
}
.tab-content {
display: none;
}
.tab-content.active {
display: block;
}
.timeframe-input {
padding: 0.75rem;
border: 1px solid #e2e8f0;
border-radius: 0.5rem;
width: 100%;
}
</style>
</head>
<body class="bg-slate-50 font-sans antialiased p-4 md:p-6">
<div class="max-w-6xl mx-auto">
<?php if (!isset($_SESSION['logged_in']) || $_SESSION['logged_in'] !== true): ?>
<!-- Login Form -->
<div class="bg-white rounded-2xl shadow-xl border border-slate-200 p-8 max-w-md mx-auto">
<h1 class="text-3xl font-bold text-slate-800 mb-6 flex items-center gap-3">
<i class="fa-solid fa-lock text-indigo-500"></i>
<span>Admin Login</span>
</h1>
<?php if (isset($login_error)): ?>
<div class="bg-red-50 text-red-700 p-3 rounded-lg mb-4"><?php echo $login_error; ?></div>
<?php endif; ?>
<form method="POST">
<div class="mb-4">
<label class="block text-sm font-medium text-slate-700 mb-1">Username</label>
<input type="text" name="username" value="admin" class="w-full border border-slate-200 rounded-lg p-3">
</div>
<div class="mb-6">
<label class="block text-sm font-medium text-slate-700 mb-1">Password</label>
<input type="password" name="password" value="pass" class="w-full border border-slate-200 rounded-lg p-3">
</div>
<button type="submit" name="login" class="w-full bg-indigo-700 hover:bg-indigo-800 text-white font-medium py-3 px-4 rounded-lg transition">
<i class="fa-solid fa-arrow-right-to-bracket mr-2"></i> Login
</button>
</form>
</div>
<?php else: ?>
<!-- Admin Panel -->
<div class="bg-white rounded-2xl shadow-xl border border-slate-200 overflow-hidden">
<div class="p-6 md:p-8">
<div class="flex flex-wrap justify-between items-center mb-6 gap-4">
<h1 class="text-3xl font-bold text-slate-800 flex items-center gap-3">
<i class="fa-solid fa-gear text-indigo-500"></i>
<span>Admin Configuration</span>
</h1>
<div class="flex gap-3">
<a href="generated_brief.html" target="_blank" class="px-4 py-2 bg-green-500 hover:bg-green-600 text-white rounded-lg transition flex items-center gap-2">
<i class="fa-regular fa-eye"></i> View Generated
</a>
<a href="?logout=1" class="px-4 py-2 bg-red-500 hover:bg-red-600 text-white rounded-lg transition flex items-center gap-2">
<i class="fa-solid fa-sign-out-alt"></i> Logout
</a>
</div>
</div>
<?php if (isset($save_success)): ?>
<div class="bg-green-50 text-green-700 p-4 rounded-lg mb-6 flex items-center gap-3">
<i class="fa-regular fa-circle-check text-xl"></i>
<?php echo $save_success; ?>
</div>
<?php endif; ?>
<!-- Navigation Tabs -->
<div class="nav-tabs">
<div class="nav-tab active" data-tab="platforms">Platforms</div>
<div class="nav-tab" data-tab="features">Features & Modules</div>
<div class="nav-tab" data-tab="extras">Extras / Add-ons</div>
<div class="nav-tab" data-tab="timeframes">Timeframes</div>
</div>
<form method="POST" id="configForm">
<!-- Platforms Tab -->
<div id="platforms" class="tab-content active">
<h2 class="text-xl font-semibold text-slate-700 mb-4">Configure Platforms</h2>
<div id="platforms-container" class="space-y-4">
<?php foreach ($config['platforms'] as $index => $platform): ?>
<div class="config-item">
<div class="config-item-header">
<span class="font-medium">Platform #<?php echo $index + 1; ?></span>
<button type="button" class="remove-btn" onclick="removeItem(this, 'platforms')"><i class="fa-regular fa-trash-can"></i></button>
</div>
<div class="item-row">
<input type="text" name="platforms[<?php echo $index; ?>][label]" value="<?php echo htmlspecialchars($platform['label']); ?>" placeholder="Label (e.g. Web)" required>
<input type="number" name="platforms[<?php echo $index; ?>][cost]" value="<?php echo $platform['cost']; ?>" placeholder="Cost" required>
<input type="text" name="platforms[<?php echo $index; ?>][value]" value="<?php echo htmlspecialchars($platform['value']); ?>" placeholder="Value (e.g. Web)" required>
</div>
</div>
<?php endforeach; ?>
</div>
<button type="button" class="add-btn mt-4" onclick="addPlatform()"><i class="fa-regular fa-plus mr-2"></i> Add Platform</button>
</div>
<!-- Features Tab -->
<div id="features" class="tab-content">
<h2 class="text-xl font-semibold text-slate-700 mb-4">Configure Features & Modules</h2>
<div id="features-container" class="space-y-4">
<?php foreach ($config['features'] as $index => $feature): ?>
<div class="config-item">
<div class="config-item-header">
<span class="font-medium">Feature #<?php echo $index + 1; ?></span>
<button type="button" class="remove-btn" onclick="removeItem(this, 'features')"><i class="fa-regular fa-trash-can"></i></button>
</div>
<div class="item-row">
<input type="text" name="features[<?php echo $index; ?>][label]" value="<?php echo htmlspecialchars($feature['label']); ?>" placeholder="Label" required>
<input type="number" name="features[<?php echo $index; ?>][cost]" value="<?php echo $feature['cost']; ?>" placeholder="Cost" required>
<input type="text" name="features[<?php echo $index; ?>][value]" value="<?php echo htmlspecialchars($feature['value']); ?>" placeholder="Value" required>
</div>
</div>
<?php endforeach; ?>
</div>
<button type="button" class="add-btn mt-4" onclick="addFeature()"><i class="fa-regular fa-plus mr-2"></i> Add Feature</button>
</div>
<!-- Extras Tab -->
<div id="extras" class="tab-content">
<h2 class="text-xl font-semibold text-slate-700 mb-4">Configure Extras / Add-ons</h2>
<div id="extras-container" class="space-y-4">
<?php foreach ($config['extras'] as $index => $extra): ?>
<div class="config-item">
<div class="config-item-header">
<span class="font-medium">Extra #<?php echo $index + 1; ?></span>
<button type="button" class="remove-btn" onclick="removeItem(this, 'extras')"><i class="fa-regular fa-trash-can"></i></button>
</div>
<div class="item-row">
<input type="text" name="extras[<?php echo $index; ?>][label]" value="<?php echo htmlspecialchars($extra['label']); ?>" placeholder="Label" required>
<input type="number" name="extras[<?php echo $index; ?>][cost]" value="<?php echo $extra['cost']; ?>" placeholder="Cost" required>
<input type="text" name="extras[<?php echo $index; ?>][value]" value="<?php echo htmlspecialchars($extra['value']); ?>" placeholder="Value" required>
</div>
</div>
<?php endforeach; ?>
</div>
<button type="button" class="add-btn mt-4" onclick="addExtra()"><i class="fa-regular fa-plus mr-2"></i> Add Extra</button>
</div>
<!-- Timeframes Tab -->
<div id="timeframes" class="tab-content">
<h2 class="text-xl font-semibold text-slate-700 mb-4">Configure Timeframes</h2>
<div class="space-y-4">
<div class="config-item">
<label class="block text-sm font-medium text-slate-700 mb-2">Low Complexity (1-4 features)</label>
<input type="text" name="timeframes[low]" value="<?php echo htmlspecialchars($config['timeframes']['low']); ?>" class="timeframe-input" placeholder="e.g. 3 Days" required>
</div>
<div class="config-item">
<label class="block text-sm font-medium text-slate-700 mb-2">Medium Complexity (5-8 features)</label>
<input type="text" name="timeframes[medium]" value="<?php echo htmlspecialchars($config['timeframes']['medium']); ?>" class="timeframe-input" placeholder="e.g. 7 Days" required>
</div>
<div class="config-item">
<label class="block text-sm font-medium text-slate-700 mb-2">High Complexity (9+ features)</label>
<input type="text" name="timeframes[high]" value="<?php echo htmlspecialchars($config['timeframes']['high']); ?>" class="timeframe-input" placeholder="e.g. 2 Weeks" required>
</div>
</div>
</div>
<!-- Hidden inputs for JSON data -->
<input type="hidden" name="sections" id="sections-input" value='<?php echo json_encode($config['sections']); ?>'>
<input type="hidden" name="platforms" id="platforms-input">
<input type="hidden" name="features" id="features-input">
<input type="hidden" name="extras" id="extras-input">
<input type="hidden" name="timeframes" id="timeframes-input">
<div class="mt-8 flex justify-end">
<button type="submit" name="save_config" class="px-8 py-3 bg-indigo-700 hover:bg-indigo-800 text-white rounded-xl shadow-md flex items-center gap-3 text-lg font-medium transition">
<i class="fa-regular fa-floppy-disk"></i> Save Configuration & Generate HTML
</button>
</div>
</form>
</div>
</div>
<?php endif; ?>
</div>
<script>
<?php if (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true): ?>
// Tab switching
document.querySelectorAll('.nav-tab').forEach(tab => {
tab.addEventListener('click', () => {
document.querySelectorAll('.nav-tab').forEach(t => t.classList.remove('active'));
document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
tab.classList.add('active');
const tabId = tab.dataset.tab;
document.getElementById(tabId).classList.add('active');
});
});
// Add functions
function addPlatform() {
const container = document.getElementById('platforms-container');
const index = container.children.length;
const html = `
<div class="config-item">
<div class="config-item-header">
<span class="font-medium">Platform #${index + 1}</span>
<button type="button" class="remove-btn" onclick="removeItem(this, 'platforms')"><i class="fa-regular fa-trash-can"></i></button>
</div>
<div class="item-row">
<input type="text" name="platforms[${index}][label]" placeholder="Label (e.g. Web)" required>
<input type="number" name="platforms[${index}][cost]" placeholder="Cost" required>
<input type="text" name="platforms[${index}][value]" placeholder="Value (e.g. Web)" required>
</div>
</div>
`;
container.insertAdjacentHTML('beforeend', html);
}
function addFeature() {
const container = document.getElementById('features-container');
const index = container.children.length;