home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2004 April
/
CMCD0404.ISO
/
Software
/
Freeware
/
Programare
/
groupoffice-com-2.01
/
modules
/
projects
/
project.php
< prev
next >
Wrap
PHP Script
|
2004-03-08
|
21KB
|
566 lines
<?php
/*
Copyright Intermesh 2003
Author: Merijn Schering <mschering@intermesh.nl>
Version: 1.0 Release date: 08 July 2003
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
*/
require("../../Group-Office.php");
$GO_SECURITY->authenticate();
$GO_MODULES->authenticate('projects');
require($GO_LANGUAGE->get_language_file('projects'));
$page_title=$lang_modules['projects'];
require($GO_CONFIG->class_path."projects.class.inc");
$projects = new projects();
$task = isset($_REQUEST['task']) ? $_REQUEST['task'] : '';
$project_id = isset($_REQUEST['project_id']) ? $_REQUEST['project_id'] : 0;
$link_back = (isset($_REQUEST['link_back']) && $_REQUEST['link_back'] != '') ? $_REQUEST['link_back'] : $_SERVER['REQUEST_URI'];
$return_to = isset($_REQUEST['return_to']) ? $_REQUEST['return_to'] : $_SERVER['HTTP_REFERER'];
//remember sorting in cookie
if (isset($_REQUEST['new_sort_field']) && $_REQUEST['new_sort_field'] != '')
{
SetCookie("no_sort_field",$_REQUEST['new_sort_field'],time()+3600*24*365,"/","",0);
$_COOKIE['no_sort_field'] = $_REQUEST['new_sort_field'];
}
if (isset($_REQUEST['new_sort_direction']) && $_REQUEST['new_sort_direction'] != '')
{
SetCookie("no_sort_direction",$_REQUEST['new_sort_direction'],time()+3600*24*365,"/","",0);
$_COOKIE['no_sort_direction'] = $_REQUEST['new_sort_direction'];
}
if (isset($_REQUEST['show']))
{
SetCookie("no_show",$_REQUEST['show'],time()+3600*24*365,"/","",0);
}
switch ($task)
{
case 'save_hours':
$_COOKIE['unit_value_cookie'] = isset($_COOKIE['unit_value_cookie']) ? $_COOKIE['unit_value_cookie'] : '';
$unit_value = isset($_GET['unit_value']) ? $_GET['unit_value'] : $_COOKIE['unit_value_cookie'];
SetCookie("registration_method_cookie",$_GET['registration_method'],time()+3600*24*365,"/","",0);
SetCookie("unit_value_cookie",$unit_value,time()+3600*24*365,"/","",0);
//translate the given date stamp to unix time
$start_date_array = explode('-',$_GET['start_date']);
$start_year = $start_date_array[2];
if ($_SESSION['GO_SESSION']['date_format'] == "m-j-Y")
{
$start_month = $start_date_array[0];
$start_day = $start_date_array[1];
}else
{
$start_month = $start_date_array[1];
$start_day = $start_date_array[0];
}
$start_time = mktime($_GET['start_hour'], $_GET['start_min'], 0, $start_month, $start_day, $start_year)-($_SESSION['GO_SESSION']['timezone']*3600);
//if user gave a number of units calulate ending time
if ($_GET['registration_method'] == 'units')
{
$end_time = $start_time + $unit_value*60*$_GET['units'];
$break_time=0;
}else
{
//translate the given date stamp to unix time
$end_date_array = explode('-',$_GET['end_date']);
$end_year = $end_date_array[2];
if ($_SESSION['GO_SESSION']['date_format'] == "m-j-Y")
{
$end_month = $end_date_array[0];
$end_day = $end_date_array[1];
}else
{
$end_month = $end_date_array[1];
$end_day = $end_date_array[0];
}
$break_time = ($_GET['break_hours']*3600)+($_GET['break_mins']*60);
$end_time = mktime($_GET['end_hour'], $_GET['end_min'], 0, $end_month, $end_day, $end_year)-($_SESSION['GO_SESSION']['timezone']*3600);;
$unit_value=0;
}
if ($end_time < $start_time)
{
$feedback = '<p class="Error">'.$pm_invalid_period.'</p>';
}elseif(!$projects->check_hours($_GET['pm_user_id'], $start_time, $end_time))
{
$feedback = '<p class="Error">'.$pm_already_booked.'</p>';
}else
{
if (!$projects->add_hours($_GET['project_id'], $_GET['pm_user_id'], $start_time, $end_time, $break_time, $unit_value, $_GET['comments']))
{
$feedback = '<p class="Error">'.$strSaveError.'</p>';
}else
{
$feedback = '<p class="Success">'.$pm_add_hours_success.'</p>';
if ($_GET['close'] == 'true')
{
header('Location: '.$return_to);
exit();
}
}
}
break;
case 'save_project':
//translate the given date stamp to unix time
$start_date = date_to_unixtime($_GET['start_date']);
$end_date = date_to_unixtime($_GET['end_date']);
if ($project_id > 0)
{
$name = trim($_GET['name']);
if ($name == '')
{
$feedback = '<p class="Error">'.$error_missing_field.'</p>';
}else
{
$existing_project = $projects->get_project_by_name($name);
if($existing_project && $existing_project['id'] != $project_id)
{
$feedback = '<p class="Error">'.$pm_project_exists.'</p>';
}elseif(!$projects->update_project($_GET['project_id'], $name, $_GET['description'], $_GET['contact_id'], $_GET['comments'], $start_date, $end_date, $_GET['status'], $_GET['responsible_user_id'], $_GET['probability'], $_GET['fee_id'], $_GET['budget']))
{
$feedback = '<p class="Error">'.$strSaveError.'</p>';
}else
{
if ($_GET['close'] == 'true')
{
header('Location: '.$return_to);
exit();
}
}
}
}else
{
$name = trim($_GET['name']);
if ($name == '')
{
$feedback = '<p class="Error">'.$error_missing_field.'</p>';
}elseif($projects->get_project_by_name($name))
{
$feedback = '<p class="Error">'.$pm_project_exists.'</p>';
}else
{
$acl_read = $GO_SECURITY->get_new_acl('Project read: '.$name);
$acl_write = $GO_SECURITY->get_new_acl('Project write: '.$name);
if ($acl_read > 0 && $acl_write > 0)
{
if ($GO_SECURITY->add_user_to_acl($GO_SECURITY->user_id, $acl_write))
{
if (!$project_id = $projects->add_project($GO_SECURITY->user_id, $name, $_GET['description'], $_GET['contact_id'], $_GET['comments'], $start_date, $end_date, $_GET['status'], $_GET['responsible_user_id'], $_GET['probability'], $_GET['fee_id'], $_GET['budget'], $acl_read, $acl_write))
{
$GO_SECURITY->delete_acl($acl_read);
$GO_SECURITY->delete_acl($acl_write);
$feedback = '<p class="Error">'.$strSaveError.'</p>';
}else
{
if ($_GET['close'] == 'true')
{
header('Location: '.$return_to);
exit();
}
}
}else
{
$GO_SECURITY->delete_acl($acl_read);
$GO_SECURITY->delete_acl($acl_write);
$feedback = '<p class="Error">'.$strSaveError.'</p>';
}
}else
{
$feedback ='<p class="Error">'.$strAclError.'</p>';
}
}
}
break;
case 'stop_timer':
$timer = $projects->get_timer($GO_SECURITY->user_id);
$timer_start_time = $timer['start_time']+($_SESSION['GO_SESSION']['timezone']*3600);
$timer_end_time = get_time();
$projects->stop_timer($GO_SECURITY->user_id);
$_COOKIE['registration_method_cookie'] = 'endtime';
SetCookie("registration_method_cookie",'endtime',time()+3600*24*365,"/","",0);
$active_tab = 1;
break;
case 'book':
$active_tab = 1;
break;
}
if ($project_id > 0)
{
$project = $projects->get_project($project_id);
$project_name = ($project['description'] == '') ? $project['name'] : $project['name'].' ('.$project['description'].')';
$tabtable = new tabtable('project_tab', $project_name, '700', '400', '120', '', true);
$tabtable->add_tab('properties', $strProperties);
$write_permissions = $GO_SECURITY->has_permission($GO_SECURITY->user_id, $project['acl_write']);
$read_permissions = $GO_SECURITY->has_permission($GO_SECURITY->user_id, $project['acl_read']);
if (!$write_permissions && !$read_permissions)
{
header('Location: '.$GO_CONFIG->host.'error_docs/403.php');
exit();
}
if ($write_permissions)
{
$tabtable->add_tab('book', $pm_enter_data);
}
$tabtable->add_tab('load', $pm_load);
if ($notes_module = $GO_MODULES->get_module('notes'))
{
if ($GO_SECURITY->has_permission($GO_SECURITY->user_id, $notes_module['acl_read']) || $GO_SECURITY->has_permission($GO_SECURITY->user_id, $notes_module['acl_write']))
{
$tabtable->add_tab('notes', $lang_modules['notes']);
}
}
$tabtable->add_tab('read_permissions', $strReadRights);
$tabtable->add_tab('write_permissions', $strWriteRights);
$is_owner = ($project['user_id'] == $GO_SECURITY->user_id) ? true : false;
}else
{
$tabtable = new tabtable('project_tab', $pm_new_project, '600', '400', '120', '', true);
$project = false;
}
if ($project && $task != 'save_project')
{
$name = $project['name'];
$contact_id = $project['contact_id'];
$comments = $project['comments'];
$start_date = date($_SESSION['GO_SESSION']['date_format'], $project['start_date']);
$end_date = date($_SESSION['GO_SESSION']['date_format'], $project['end_date']);
$status = $project['status'];
$responsible_user_id = $project['res_user_id'];
$probability = $project['probability'];
$fee_id = $project['fee_id'];
$budget = $project['budget'];
$description = $project['description'];
if (isset($active_tab))
{
$tabtable->set_active_tab($active_tab);
}
}else
{
$name = isset($_GET['name']) ? smartstrip($_GET['name']) : '';
$contact_id = isset($_GET['contact_id']) ? $_GET['contact_id'] : '0';
$comments = isset($_GET['comments']) ? smartstrip($_GET['comments']) : '';
$start_date = isset($_GET['start_date']) ? $_GET['start_date'] : date($_SESSION['GO_SESSION']['date_format'], get_time());
$end_date = isset($_GET['end_date']) ? $_GET['end_date'] : date($_SESSION['GO_SESSION']['date_format'], get_time());
$status = isset($_GET['status']) ? $_GET['status'] : '-3';
$responsible_user_id = isset($_GET['responsible_user_id']) ? $_GET['responsible_user_id'] : 0;
$fee_id = isset($_GET['fee_id']) ? $_GET['fee_id'] : 0;
$probability = isset($_GET['probability']) ? $_GET['probability'] : 0;
$budget = isset($_GET['budget']) ? $_GET['budget'] : 0;
$description = isset($_GET['description']) ? smartstrip($_GET['description']) : '';
}
$datepicker = new date_picker();
$GO_HEADER['head'] = $datepicker->get_header();
$page_title = $lang_modules['projects'];
require($GO_THEME->theme_path."header.inc");
echo '<form method="get" action="'.$_SERVER['PHP_SELF'].'" name="projects_form">';
echo '<input type="hidden" name="close" value="false" />';
echo '<input type="hidden" name="project_id" value="'.$project_id.'" />';
echo '<input type="hidden" name="task" value="" />';
echo '<input type="hidden" name="return_to" value="'.$return_to.'" />';
$tabtable->print_head();
switch($tabtable->get_active_tab_id())
{
case 'read_permissions':
print_acl($project['acl_read']);
echo '<br />';
$button = new button($cmdClose, "javascript:document.location='".$return_to."';");
break;
case 'write_permissions':
print_acl($project['acl_write']);
echo '<br />';
$button = new button($cmdClose, "javascript:document.location='".$return_to."';");
break;
case 'book':
require('book.inc');
break;
case 'load':
$fixed_project_id = $project_id;
require('load.inc');
break;
case 'notes':
$contact_id=0;
echo '<input type="hidden" name="sort_cookie_prefix" value="no_" />';
require($GO_LANGUAGE->get_language_file('notes'));
require_once($GO_CONFIG->class_path.'notes.class.inc');
$notes = new notes();
$notes_module_url = $notes_module['url'];
$link_back .= '&active_tab=4';
require($GO_CONFIG->root_path.$notes_module['path'].'notes.inc');
echo '<br />';
$button = new button($cmdClose, "javascript:document.location='".$return_to."'");
break;
default:
if (isset($feedback)) echo $feedback;
?>
<table border="0" cellspacing="0" cellpadding="4">
<tr>
<td><?php echo $strName; ?>:</td>
<td>
<?php
if ($project_id < 1 || $is_owner)
{
echo '<input type="text" class="textbox" style="width: 250px;" name="name" value="'.$name.'" maxlength="50" />';
}else
{
echo $project['name'];
}
?>
</td>
<tr>
<tr>
<td><?php echo $pm_description; ?>:</td>
<td>
<?php
if ($project_id < 1 || $is_owner)
{
echo '<input type="text" class="textbox" style="width: 250px;" name="description" value="'.$description.'" maxlength="50" />';
}else
{
echo $project['description'];
}
?>
</td>
<tr>
<?php
require_once($GO_CONFIG->class_path.'addressbook.class.inc');
$ab = new addressbook();
if ($project_id < 1 || $project['user_id'] == $GO_SECURITY->user_id)
{
$contacts_module = $GO_MODULES->get_module('addressbook');
if($has_contacts_module = ($contacts_module && ($GO_SECURITY->has_permission($GO_SECURITY->user_id, $contacts_module['acl_read']) || $GO_SECURITY->has_permission($GO_SECURITY->user_id, $contacts_module['acl_write']))))
{
if ($contact_id > 0 && $contact = $ab->get_contact($contact_id))
{
$middle_name = $contact['middle_name'] == '' ? '' : $contact['middle_name'].' ';
$contact_name = $contact['first_name'].' '.$middle_name.$contact['last_name'];
}else
{
$contact_name = isset($_GET['contact_name']) ? $_GET['contact_name'] : '';
}
echo '<tr><td><table border="0" cellpadding="0" cellspacing="0"><tr><td><a class="normal" href="javascript:popup(\''.$contacts_module['url'].'select.php?multiselect=false&GO_HANDLER='.$GO_MODULES->url.'add_client.php&pass_value=id&show_contacts=true\',\'550\',\'400\')"><img src="'.$GO_THEME->images['addressbook_small'].'" width="16" height="16" border="0" /></a> </td><td><a class="normal" href="javascript:popup(\''.$contacts_module['url'].'select.php?multiselect=false&GO_HANDLER='.$GO_MODULES->url.'add_client.php&pass_value=id&show_contacts=true\',\'550\',\'400\')">'.$pm_client.'</a>: </td></tr></table></td>';
echo '<td><input type="hidden" value="'.$contact_id.'" name="contact_id" /><input type="hidden" value="'.$contact_name.'" name="contact_name" /><input type="text" name="contact_name_text" class="textbox" style="width: 250px;" value="'.$contact_name.'" disabled>';
echo " <a href='javascript:remove_client()' title=\"".$strDeleteItem."\"><img src=\"".$GO_THEME->images['delete']."\" border=\"0\"></a></td></tr>";
}else
{
echo '<input type="hidden" value="0" name="contact_id" />';
echo $pm_no_contact;
}
require_once($GO_CONFIG->class_path.'users.class.inc');
$users = new users();
$ab_module = $GO_MODULES->get_module('addressbook');
if ($responsible_user_id > 0 && $user = $users->get_user($responsible_user_id))
{
$middle_name = $user['middle_name'] == '' ? '' : $user['middle_name'].' ';
$user_name = $user['first_name'].' '.$middle_name.$user['last_name'];
}else
{
$user_name = isset($_REQUEST['user_name']) ? $_REQUEST['user_name'] : '';
}
echo '<tr><td><table border="0" cellpadding="0" cellspacing="0"><tr><td><a class="normal" href="javascript:popup(\''.$ab_module['url'].'select.php?show_users=true&multiselect=false&GO_HANDLER='.$GO_MODULES->url.'select_responsible_user.php&pass_value=id\',\'550\',\'400\')"><img src="'.$GO_THEME->images['addressbook_small'].'" width="16" height="16" border="0" /></a> </td><td><a class="normal" href="javascript:popup(\''.$ab_module['url'].'select.php?show_users=true&multiselect=false&GO_HANDLER='.$GO_MODULES->url.'select_responsible_user.php&pass_value=id\',\'550\',\'400\')">'.$pm_responsible.'</a>: </td></tr></table></td>';
echo '<td><input type="hidden" value="'.$responsible_user_id.'" name="responsible_user_id" /><input type="hidden" value="'.$user_name.'" name="user_name" /><input type="text" name="user_name_text" class="textbox" style="width: 250px;" value="'.$user_name.'" disabled>';
echo " <a href='javascript:remove_user()' title=\"".$strDeleteItem."\"><img src=\"".$GO_THEME->images['delete']."\" border=\"0\"></a></td></tr>";
echo '</td></tr>';
echo '<tr><td>'.$pm_start_date.':</td><td>';
$datepicker->print_date_picker('start_date', $_SESSION['GO_SESSION']['date_format'], $start_date);
echo '</td></tr>';
echo '<tr><td>'.$pm_end_date.':</td><td>';
$datepicker->print_date_picker('end_date', $_SESSION['GO_SESSION']['date_format'], $end_date);
echo '</td></tr>';
echo '<tr><td>'.$pm_status.'</td><td>';
$dropbox= new dropbox();
$dropbox->add_value(STATUS_OFFER, $pm_status_values[STATUS_OFFER]);
$dropbox->add_value(STATUS_ONGOING, $pm_status_values[STATUS_ONGOING]);
$dropbox->add_value(STATUS_WAITING, $pm_status_values[STATUS_WAITING]);
$dropbox->add_value(STATUS_DONE, $pm_status_values[STATUS_DONE]);
$dropbox->add_value(STATUS_BILLED, $pm_status_values[STATUS_BILLED]);
$dropbox->print_dropbox('status', $status);
echo '</td></tr>';
echo '<tr><td>'.$pm_probability.'</td><td>';
$dropbox= new dropbox();
for ($i=0;$i<=100;$i=$i+10)
{
$dropbox->add_value($i, $i.'%');
}
$dropbox->print_dropbox('probability', $probability);
echo '</td></tr>';
echo '<tr><td colspan="2"> </td></tr>';
echo '<tr><td>'.$pm_budget.'</td><td><input type="text" class="textbox" size="10" name="budget" value="'.$budget.'" maxlength="50" /> '.$_SESSION['GO_SESSION']['currency'].'</td></tr>';
}else
{
echo '<tr><td>'.$pm_client.':</td><td>';
if($contact_id > 0)
{
echo show_contact($contact_id);
}else
{
echo $pm_no_contact;
}
echo '</td></tr>';
echo '<tr><td>'.$pm_start_date.':</td><td>';
echo $start_date;
echo '</td></tr>';
echo '<tr><td>'.$pm_end_date.':</td><td>';
echo $end_date;
echo '</td></tr>';
echo '<tr><td>'.$pm_status.'</td><td>';
$status = ($projects->f('status') > 0 && $projects->f('status') < 101) ? $projects->f('status').'%' : $pm_status_values[(int) $projects->f('status')];
echo $status.'</td></tr>';
echo '<tr><td>'.$pm_probability.'</td><td>'.$probability.'%</td></tr>';
echo '<tr><td colspan="2"> </td></tr>';
echo '<tr><td>'.$pm_budget.'</td><td>'.$budget.' '.$_SESSION['GO_SESSION']['currency'].'</td></tr>';
}
$fee_count = $projects->get_fees();
if ($fee_count > 0)
{
echo '<tr><td>'.$pm_fee.'</td><td>';
$fee_id = isset($_POST['fee_id']) ? $_POST['fee_id'] : 0;
$dropbox=new dropbox();
while ($projects->next_record())
{
$dropbox->add_value($projects->f('id'),$projects->f('name').' ('.htmlentities($_SESSION['GO_SESSION']['currency']).' '.number_format($projects->f('value'), 2, $_SESSION['GO_SESSION']['decimal_seperator'],$_SESSION['GO_SESSION']['thousands_seperator']).' / '.$projects->f('time').' '.$pm_mins.')');
}
$disabled = ($project_id < 1 || $project['user_id'] == $GO_SECURITY->user_id) ? '' : 'disabled';
$dropbox->print_dropbox('fee_id', $fee_id, $disabled);
echo '</td><td colspan="2"> </td></tr>';
}else
{
echo '<input type="hidden" name="fee_id" value="0" />';
}
echo '<tr><td colspan="2"> </td></tr>';
if ($project_id > 0)
{
echo '<tr><td>'.$strOwner.':</td><td>'.show_profile($project['user_id']).'</td></tr>';
echo '<tr><td>'.$strCreatedAt.':</td><td>'.date($_SESSION['GO_SESSION']['date_format'].' '.$_SESSION['GO_SESSION']['time_format'], $project['ctime']+($_SESSION['GO_SESSION']['timezone']*3600)).'</td><tr>';
echo '<tr><td>'.$strModifiedAt.':</td><td>'.date($_SESSION['GO_SESSION']['date_format'].' '.$_SESSION['GO_SESSION']['time_format'], $project['mtime']+($_SESSION['GO_SESSION']['timezone']*3600)).'</td><tr>';
echo '<tr><td colspan="2"> </td></tr>';
}
?>
<tr>
<td valign="top"><?php echo $strComments; ?>:</td>
<td>
<?php
if ($project_id < 1 || $project['user_id'] == $GO_SECURITY->user_id)
{
echo '<textarea name="comments" cols="50" rows="4" class="textbox">'.$comments.'</textarea>';
}else
{
echo text_to_html($comments);
}
?>
</td>
</tr>
<tr>
<td colspan="2">
<?php
if ($project_id < 1 || $is_owner)
{
$button = new button($cmdOk, "javascript:_save('save_project', 'true');");
echo ' ';
$button = new button($cmdApply, "javascript:_save('save_project', 'false')");
echo ' ';
}
$button = new button($cmdClose, "javascript:document.location='".$return_to."';");
?>
</td>
</tr>
</table>
<?php
break;
}
$tabtable->print_foot();
echo '</form>';
?>
<script type="text/javascript">
function _save(task, close)
{
document.projects_form.task.value = task;
document.projects_form.close.value = close;
document.projects_form.submit();
}
function remove_client()
{
document.projects_form.contact_id.value = 0;
document.projects_form.contact_name.value = '';
document.projects_form.contact_name_text.value = '';
}
function remove_user()
{
document.projects_form.responsible_user_id.value = 0;
document.projects_form.user_name.value = '';
document.projects_form.user_name_text.value = '';
}
</script>
<?php
require($GO_THEME->theme_path."footer.inc");
?>