5 * Copyright 1999-2001 (c) VA Linux Systems
6 * Copyright 2002-2004 (c) GForge Team
7 * Copyright 2010 (c) Franck Villaume
8 * Copyright (C) 2010 Alain Peyrat - Alcatel-Lucent
9 * Copyright 2013-2016, Franck Villaume - TrivialDev
10 * http://fusionforge.org/
12 * This file is part of FusionForge. FusionForge is free software;
13 * you can redistribute it and/or modify it under the terms of the
14 * GNU General Public License as published by the Free Software
15 * Foundation; either version 2 of the Licence, or (at your option)
18 * FusionForge is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 function people_header($params) {
29 global $group_id, $job_id, $HTML;
32 $params['toptab'] = 'people';
33 $params['group'] = $group_id;
34 site_project_header($params);
35 } elseif (isset($_SERVER['HTTP_REFERER']) && strstr($_SERVER['HTTP_REFERER'], 'account')) {
36 $params['toptab'] = 'my';
37 site_user_header($params);
39 $HTML->header($params);
42 if ($group_id && $job_id) {
43 echo ' | '.util_make_link ('/people/editjob.php?group_id='. $group_id .'&job_id='. $job_id,_('Edit Job'));
47 function people_footer($params = array()) {
49 $HTML->footer($params);
52 function people_skill_box($name='skill_id',$checked='xzxz') {
55 //will be used many times potentially on a single page
56 $PEOPLE_SKILL=db_query_params("SELECT * FROM people_skill ORDER BY name ASC", array());
58 return html_build_select_box($PEOPLE_SKILL,$name,$checked,false);
61 function people_skill_level_box($name='skill_level_id',$checked='xzxz') {
62 global $PEOPLE_SKILL_LEVEL;
63 if (!$PEOPLE_SKILL_LEVEL) {
64 //will be used many times potentially on a single page
65 $PEOPLE_SKILL_LEVEL=db_query_params("SELECT * FROM people_skill_level", array());
67 return html_build_select_box($PEOPLE_SKILL_LEVEL,$name,$checked, false);
70 function people_skill_year_box($name='skill_year_id',$checked='xzxz') {
71 global $PEOPLE_SKILL_YEAR;
72 if (!$PEOPLE_SKILL_YEAR) {
73 //will be used many times potentially on a single page
74 $PEOPLE_SKILL_YEAR=db_query_params("SELECT * FROM people_skill_year", array());
76 return html_build_select_box($PEOPLE_SKILL_YEAR,$name,$checked, false);
79 function people_job_status_box($name='status_id',$checked='xzxz') {
80 $result=db_query_params("SELECT * FROM people_job_status", array());
81 return html_build_select_box ($result,$name,$checked);
84 function people_job_category_box($name='category_id',$checked='xzxz') {
85 $result=db_query_params("SELECT category_id,name FROM people_job_category WHERE private_flag=0", array());
86 return html_build_select_box($result, $name, $checked, false);
89 function people_add_to_skill_inventory($skill_id,$skill_level_id,$skill_year_id) {
93 if (session_loggedin()) {
94 // check required fields
95 if (!$skill_id || $skill_id == 'xzxz') {
96 $feedback .= _('Must select a skill ID');
98 //check if they've already added this skill
99 $result=db_query_params("SELECT * FROM people_skill_inventory WHERE user_id=$1 AND skill_id=$2", array(user_getid(), $skill_id));
100 if (!$result || db_numrows($result) < 1) {
101 //skill not already in inventory
102 $result = db_query_params("INSERT INTO people_skill_inventory (user_id,skill_id,skill_level_id,skill_year_id)
103 VALUES ($1, $2, $3, $4)", array(user_getid() ,$skill_id, $skill_level_id, $skill_year_id));
104 if (!$result || db_affected_rows($result) < 1) {
105 $error_msg .= _('Error inserting into skill inventory')._(': ');
106 $error_msg .= db_error();
108 $feedback .= _('Added to skill inventory');
111 $error_msg .= _('Error')._(': ')._('skill already in your inventory');
115 echo $HTML->error_msg(_('You must be logged in first'));
119 function people_show_skill_inventory($user_id) {
121 $result = db_query_params("SELECT people_skill.name AS skill_name, people_skill_level.name AS level_name, people_skill_year.name AS year_name
122 FROM people_skill_year,people_skill_level,people_skill,people_skill_inventory
123 WHERE people_skill_year.skill_year_id=people_skill_inventory.skill_year_id
124 AND people_skill_level.skill_level_id=people_skill_inventory.skill_level_id
125 AND people_skill.skill_id=people_skill_inventory.skill_id
126 AND people_skill_inventory.user_id=$1", array($user_id));
129 $title_arr[]=_('Skill');
130 $title_arr[]=_('Level');
131 $title_arr[]=_('Experience');
134 echo $HTML->listTableTop($title_arr);
136 $rows=db_numrows($result);
137 if (!$result || $rows < 1) {
139 <h2>'._('No Skill Inventory Set Up').'</h2>';
142 for ($i=0; $i < $rows; $i++) {
145 <td>'.db_result($result,$i,'skill_name').'</td>
146 <td>'.db_result($result,$i,'level_name').'</td>
147 <td>'.db_result($result,$i,'year_name').'</td></tr>';
152 echo $HTML->listTableBottom();
155 function people_edit_skill_inventory($user_id) {
157 $result=db_query_params('SELECT * FROM people_skill_inventory WHERE user_id=$1', array($user_id));
160 $title_arr[]=_('Skill');
161 $title_arr[]=_('Level');
162 $title_arr[]=_('Experience');
163 $title_arr[]=_('Action');
165 echo $HTML->listTableTop($title_arr);
167 $rows=db_numrows($result);
168 if (!$result || $rows < 1) {
170 <tr><td colspan="4">'._('No skill setup').'</h2></td></tr>';
173 for ($i=0; $i < $rows; $i++) {
174 echo $HTML->openForm(array('action' => getStringFromServer('PHP_SELF'), 'method' => 'post'));
176 <input type="hidden" name="skill_inventory_id" value="'.db_result($result,$i,'skill_inventory_id').'" />
178 <td>'. people_get_skill_name(db_result($result,$i,'skill_id')) .'</td>
179 <td>'. people_skill_level_box('skill_level_id',db_result($result,$i,'skill_level_id')). '</td>
180 <td>'. people_skill_year_box('skill_year_id',db_result($result,$i,'skill_year_id')). '</td>
181 <td style="white-space:nowrap"><input type="submit" name="update_skill_inventory" value="'._('Update').'" />
182 <input type="submit" name="delete_from_skill_inventory" value="'._('Delete').'" /></td>
184 echo $HTML->closeForm();
189 $i++; //for row coloring
191 echo '<tr class="tableheading"><td colspan="4">'._('Add a new skill').'/td></tr>';
192 echo $HTML->openForm(array('action' => getStringFromServer('PHP_SELF'), 'method' => 'post'));
194 <td>'. people_skill_box('skill_id'). '</td>
195 <td>'. people_skill_level_box('skill_level_id'). '</td>
196 <td>'. people_skill_year_box('skill_year_id'). '</td>
197 <td nowrap="nowrap"><input type="submit" name="add_to_skill_inventory" value="'._('Add Skill').'" /></td>
199 echo $HTML->closeForm();
200 echo $HTML->listTableBottom();
205 function people_add_to_job_inventory($job_id,$skill_id,$skill_level_id,$skill_year_id) {
206 global $feedback, $error_msg, $HTML;
207 if (session_loggedin()) {
208 // check if they've already added this job
209 $result=db_query_params('SELECT * FROM people_job_inventory WHERE job_id=$1 AND skill_id=$2', array($job_id, $skill_id));
210 if (!$result || db_numrows($result) < 1) {
211 // job is not yet in this inventory
212 $result=db_query_params('INSERT INTO people_job_inventory (job_id,skill_id,skill_level_id,skill_year_id)
213 VALUES ($1, $2, $3, $4)',
214 array($job_id, $skill_id, $skill_level_id, $skill_year_id));
215 if (!$result || db_affected_rows($result) < 1) {
216 $error_msg .= _('Error inserting into job inventory')._(': ');
217 $error_msg .= db_error();
220 $feedback .= _('Added to job inventory');
224 $error_msg .= _('Error')._(': ')._('skill already in your inventory');
229 echo $HTML->error_msg(_('You must be logged in first'));
234 function people_show_job_inventory($job_id) {
236 $result=db_query_params('SELECT people_skill.name AS skill_name, people_skill_level.name AS level_name, people_skill_year.name AS year_name
237 FROM people_skill_year,people_skill_level,people_skill,people_job_inventory
238 WHERE people_skill_year.skill_year_id=people_job_inventory.skill_year_id
239 AND people_skill_level.skill_level_id=people_job_inventory.skill_level_id
240 AND people_skill.skill_id=people_job_inventory.skill_id
241 AND people_job_inventory.job_id=$1', array($job_id));
244 $title_arr[]=_('Skill');
245 $title_arr[]=_('Level');
246 $title_arr[]=_('Experience');
248 echo $HTML->listTableTop($title_arr);
250 $rows=db_numrows($result);
251 if (!$result || $rows < 1) {
253 <tr><td><h2>'._('No Skill Inventory Set Up').'</h2></td></tr>';
256 for ($i=0; $i < $rows; $i++) {
259 <td>'.db_result($result,$i,'skill_name').'</td>
260 <td>'.db_result($result,$i,'level_name').'</td>
261 <td>'.db_result($result,$i,'year_name').'</td>
267 echo $HTML->listTableBottom();
271 function people_verify_job_group($job_id,$group_id) {
272 $result=db_query_params('SELECT * FROM people_job WHERE job_id=$1 AND group_id=$2', array($job_id, $group_id));
273 if (!$result || db_numrows($result) < 1) {
280 function people_get_skill_name($skill_id) {
281 $result=db_query_params('SELECT name FROM people_skill WHERE skill_id=$1', array($skill_id));
282 if (!$result || db_numrows($result) < 1) {
283 return _('Invalid ID');
285 return db_result($result,0,'name');
289 function people_get_category_name($category_id) {
290 $result=db_query_params('SELECT name FROM people_job_category WHERE category_id=$1', array($category_id));
291 if (!$result || db_numrows($result) < 1) {
292 return _('Invalid ID');
294 return db_result($result,0,'name');
299 // This function does not produce valid XHTML; however, I could not
300 // think of a way of turning into valid XHTML without the resulting
301 // table looking like poo.
302 function people_edit_job_inventory($job_id,$group_id) {
304 $result=db_query_params('SELECT * FROM people_job_inventory WHERE job_id=$1', array($job_id));
307 $title_arr[]=_('Skill').utils_requiredField();
308 $title_arr[]=_('Level').utils_requiredField();
309 $title_arr[]=_('Experience').utils_requiredField();
310 $title_arr[]=_('Action');
312 echo $HTML->listTableTop($title_arr);
314 $rows=db_numrows($result);
315 if (!$result || $rows < 1) {
317 exit_error(db_error(),'admin');
319 echo '<tr><td colspan="4"><h2>'._('No Skill Inventory Set Up').'</h2></td></tr>';
322 for ($i=0; $i < $rows; $i++) {
324 echo $HTML->openForm(array('action' => getStringFromServer('PHP_SELF'), 'method' => 'post'));
325 echo '<input type="hidden" name="job_inventory_id" value="'. db_result($result,$i,'job_inventory_id') .'" />
326 <input type="hidden" name="job_id" value="'. db_result($result,$i,'job_id') .'" />
327 <input type="hidden" name="group_id" value="'.$group_id.'" />
328 <td style="width: 25%">'. people_get_skill_name(db_result($result,$i,'skill_id')) . '</td>
329 <td style="width: 25%">'. people_skill_level_box('skill_level_id',db_result($result,$i,'skill_level_id')). '</td>
330 <td style="width: 25%">'. people_skill_year_box('skill_year_id',db_result($result,$i,'skill_year_id')). '</td>
331 <td style="width: 25%" nowrap="nowrap"><input type="submit" name="update_job_inventory" value="'._('Update').'" />
332 <input type="submit" name="delete_from_job_inventory" value="'._('Delete').'" /></td>'.
333 $HTML->closeForm().'</tr>';
338 (isset($i)) ? $i++ : $i = 0; //for row coloring
340 echo '<tr><td colspan="4"><h3>'._('Add a new skill').'</h3></td></tr>
342 echo $HTML->openForm(array('action' => getStringFromServer('PHP_SELF'), 'method' => 'post'));
343 echo '<input type="hidden" name="job_id" value="'. $job_id .'" />
344 <input type="hidden" name="group_id" value="'.$group_id.'" />
345 <td style="width: 25%">'. people_skill_box('skill_id'). '</td>
346 <td style="width: 25%">'. people_skill_level_box('skill_level_id'). '</td>
347 <td style="width: 25%">'. people_skill_year_box('skill_year_id'). '</td>
348 <td style="width: 25%" nowrap="nowrap"><input type="submit" name="add_to_job_inventory" value="'._('Add Skill').'" /></td>'.
349 $HTML->closeForm().'</tr>';
350 echo $HTML->listTableBottom();
353 function people_show_category_table() {
355 //show a list of categories in a table
356 //provide links to drill into a detail page that shows these categories
358 $title_arr = array();
359 $title_arr[] = _('Category');
361 $result= db_query_params('SELECT pjc.category_id, pjc.name, COUNT(pj.category_id) AS total, pj.group_id
362 FROM people_job_category pjc LEFT JOIN people_job pj
363 ON pjc.category_id=pj.category_id
364 WHERE pjc.private_flag=0
365 AND (pj.status_id=1 OR pj.status_id IS NULL)
366 GROUP BY pjc.category_id, pjc.name, pj.group_id', array());
368 $categories = array();
370 while ($arr = db_fetch_array($result)) {
372 if (empty($arr['group_id']) || forge_check_perm('project_read', $arr['group_id'])) {
373 $categories[$i] = $arr;
376 if ($added && ((count($categories) - 1) > 0)) {
377 for ($j = 0; $j < (count($categories) - 1); $j++) {
379 if ($categories[$j]['category_id'] == $categories[$i]['category_id']) {
380 $categories[$j]['total'] += $categories[$i]['total'];
386 array_pop($categories);
395 if (count($categories) < 1) {
396 $return = $HTML->warning_msg(_('No categories found.'));
398 $return = $HTML->listTableTop($title_arr);
399 for ($i = 0; $i< count($categories); $i++) {
401 <td>'.util_make_link('/people/?category_id='.$categories[$i]['category_id'], $categories[$i]['name']).' ('.$categories[$i]['total'].')</td>
405 $return .= $HTML->listTableBottom();
409 function people_show_project_jobs($group_id) {
410 //show open jobs for this project
411 $result = db_query_params('SELECT people_job.group_id,people_job.job_id,groups.group_name,groups.unix_group_name,people_job.title,people_job.post_date,people_job_category.name AS category_name
412 FROM people_job,people_job_category,groups
413 WHERE people_job.group_id=$1
414 AND people_job.group_id=groups.group_id
415 AND people_job.category_id=people_job_category.category_id
416 AND people_job.status_id=1 ORDER BY post_date DESC', array($group_id));
418 return people_show_job_list($result);
421 function people_show_category_jobs($category_id) {
422 //show open jobs for this category
423 $result=db_query_params('SELECT people_job.group_id,people_job.job_id,groups.unix_group_name,groups.group_name,people_job.title,people_job.post_date,people_job_category.name AS category_name
424 FROM people_job,people_job_category,groups
425 WHERE people_job.category_id=$1
426 AND people_job.group_id=groups.group_id
427 AND people_job.category_id=people_job_category.category_id
428 AND people_job.status_id=1 ORDER BY post_date DESC', array($category_id));
430 return people_show_job_list($result);
433 function people_show_job_list($result) {
435 //takes a result set from a query and shows the jobs
437 //query must contain 'group_id', 'job_id', 'title', 'category_name' and 'status_name'
439 $title_arr = array();
440 $title_arr[] = _('Title');
441 $title_arr[] = _('Category');
442 $title_arr[] = _('Date Opened');
443 $title_arr[] = sprintf(_('%s project'), forge_get_config('forge_name'));
446 while ($arr = db_fetch_array($result)) {
447 if (forge_check_perm('project_read', $arr['group_id'])) {
452 if (count($projects) < 1) {
453 $return = $HTML->warning_msg(_('None Found'));
455 $return = $HTML->listTableTop($title_arr);
456 for ($i = 0; $i < count($projects); $i++) {
459 <td>'.util_make_link('/people/viewjob.php?group_id='.$projects[$i]['group_id'].'&job_id='.$projects[$i]['job_id'], $projects[$i]['title']) .'</td>
460 <td>'.$projects[$i]['category_name'].'</td>
461 <td>'.date(_('Y-m-d H:i'), $projects[$i]['post_date']).'</td>
462 <td>'.util_make_link_g(strtolower($projects[$i]['unix_group_name']), $projects[$i]['group_id'], $projects[$i]['group_name']).'</td>
465 $return .= $HTML->listTableBottom();
470 function people_group_has_job($group_id) {
471 $res = db_query_params('SELECT count(*) as count FROM people_job WHERE group_id = $1', array($group_id));
472 $row_count = db_fetch_array($res);
473 return (int)$row_count['count'];
478 // c-file-style: "bsd"