-
Notifications
You must be signed in to change notification settings - Fork 0
/
tech_profile_edit.php
127 lines (119 loc) · 4.12 KB
/
tech_profile_edit.php
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
<?php
// This file is part of Music Match.
// Copyright (C) 2022 David P. Anderson
//
// Music Match is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// Music Match is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Music Match. If not, see <http://www.gnu.org/licenses/>.
// --------------------------------------------------------------------
// create/edit a technician profile
require_once("../inc/util.inc");
require_once("../inc/mm.inc");
require_once("../inc/notification.inc");
function tech_form($user) {
$profile = read_profile($user->id, TECHNICIAN);
page_head("Technician profile");
form_start("tech_profile_edit.php", "POST");
form_checkboxes(
"My areas of expertise",
array_merge(
items_list(TECH_AREA_LIST, $profile->tech_area, "tech_area"),
items_custom($profile->tech_area_custom, "tech_area_custom")
)
);
form_input_text(
'', 'tech_area_custom_new', TECH_AREA_ADD, 'text',
text_input_default(TECH_AREA_ADD).'class="sm" size="20"'
);
form_checkboxes(
"Software I'm familiar with",
array_merge(
items_list(PROGRAM_LIST, $profile->program, "program"),
items_custom($profile->program_custom, "program_custom")
)
);
form_input_text(
'', 'program_custom_new', PROGRAM_ADD, 'text',
text_input_default(PROGRAM_ADD).'class="sm" size="20"'
);
form_input_textarea(
'Introduction<br><small>My background as a technician</small>',
'description',
$profile->description,
3
);
form_checkboxes('I usually get paid for my services',
array(array('tech_paid', '', $profile->tech_paid))
);
$have_profile = profile_exists($user->id, TECHNICIAN);
form_submit($have_profile?"Update profile":"Create profile", 'name=submit value=on');
form_end();
if ($have_profile) {
echo "<p>";
mm_show_button(
"tech_profile_edit.php?&action=delete",
"Delete profile",
BUTTON_SMALL
);
}
page_tail();
}
function tech_action($user_id, $profile) {
$profile2 = new StdClass;
$profile2->tech_area = parse_list(TECH_AREA_LIST, 'tech_area');
$profile2->tech_area_custom = parse_custom(
$profile->tech_area_custom, "tech_area_custom", TECH_AREA_ADD
);
$profile2->program = parse_list(PROGRAM_LIST, "program");
$profile2->program_custom = parse_custom(
$profile->program_custom, "program_custom", PROGRAM_ADD
);
$profile2->description = strip_tags(post_str('description'));
$profile2->tech_paid = parse_post_bool('tech_paid');
return $profile2;
}
function confirm_form() {
page_head('Confirm delete profile');
echo '<p>Are you sure you want to delete your Technician profile?';
echo "<p>";
mm_show_button("tech_profile_edit.php?action=confirm",
"Delete profile",
BUTTON_DANGER
);
echo "<p>";
page_tail();
}
function do_delete_profile($user) {
page_head("Profile deleted");
delete_mm_profile($user->id, TECHNICIAN);
echo 'Your Technician profile has been deleted.';
page_tail();
}
$user = get_logged_in_user();
update_visit_time($user);
if (post_str('submit', true)) {
$profile = read_profile($user->id, TECHNICIAN);
$profile = tech_action($user->id, $profile);
write_profile($user->id, $profile, TECHNICIAN);
notify_profile_change($user, TECHNICIAN);
Header("Location: home.php");
} else {
$action = get_str('action', true);
if ($action == 'delete') {
confirm_form();
} else if ($action == 'confirm') {
do_delete_profile($user, TECHNICIAN);
} else {
tech_form($user);
}
}
?>