<?php
/*
Task management
(c) 2004-2007 by "Oleg Savchuk" <hide@address.com>
part of phpProjectMaster project
http://phpprojmaster.sourceforge.net
The contents of this file are subject to the GNU GENERAL PUBLIC LICENSE
http://www.gnu.org/copyleft/gpl.html
*/
session_start();
require_once "../inc/sitelib.php" ;
require_once "../inc/form_utils.php" ;
require_once "../inc/image_utils.php" ;
require_once "../inc/user.php" ;
require_once "../inc/task.lib.php" ;
require_once "../inc/comm.lib.php" ;
require_once "../inc/att.lib.php" ;
global_init();
check_access(0); #!important to call AFTER global_init, so permanent autologin can be done
//********* variables
$tbl_name = $task_vars['table_name'];
$tbl_key = $task_vars['table_key_id'];
$item_id = $_REQUEST['id']+0;
$is_my = get_page_option('my', $tbl_name."_is_my",'str');
if ($is_my!=0 && $is_my!=1) $is_my=1;
if ($_SESSION['access_level']<100) $is_my=1; #!!!TODO - base on user rights
$is_ass = get_page_option('ass', $tbl_name."_is_ass",'str'); #Assign Tasks mode - show people who I assigned
if ($is_ass!=0 && $is_ass!=1) $is_ass=0;
$this_tpl_dir = '/admin/task';
$tbl_fields = 'p_id parent_t_id u_id is_private iname idesc perc_compl prio_id start_time end_time end_time2 build_opened build_fixed severity status'; //fields to save
$SORTSQL=array(
'prio' => 'p.sort_order',
'type' => 't.itype',
'emp' => 't.u_id',
'status' => 't.status',
'id' => 't.t_id',
'iname' => 't.iname',
'add_time' => 't.add_time desc',
);
//********* action!
$CGI_ACTIONS=array(
'' => 'show_item_list',
'SaveList' => 'save_item_list',
'AddNew' => 'show_one_item',
'Edit' => 'show_one_item',
'SaveRec' => 'save_one_item',
'DelRec' => 'delete_item',
'DelRecAtt' => 'delete_attach',
'SaveRecComm' => 'save_comm_item',
'DelRecCommAtt' => 'delete_attach_comm',
'GoPrev' => 'goto_item',
'GoNext' => 'goto_item',
'AjaxFlag' => 'ajax_mark_task_flag',
);
go_action();
exit;
//***************************
function show_item_list(){
global $task_vars;
global $tbl_name, $tbl_key, $is_my, $is_ass;
global $this_script, $this_tpl_dir, $root_url, $MAX_PAGE_ITEMS, $SORTSQL;
$moreurl=''; //additional url params for nav
$where=" ";
$status=get_page_option('status', $tbl_name."_status",'str');
if (strlen($status)) {
$where.=" t.status=".dbq($status);
} else{
$where.=" t.status<>127";
}
//******** filter options
$itype=get_page_option('itype', $tbl_name."_itype",'str');
if (strlen($itype)) $where.=" and t.itype=".dbq($itype);
$p_id=get_page_option('p_id', $tbl_name."_p_id");
if ($p_id>0) $where.=" and t.p_id=$p_id";
$u_id=get_page_option('u_id', $tbl_name."_u_id");
# if ($is_my) $u_id=$_SESSION['u_id']; #!!!TODO - decide if to limit or not employee's view
if ($u_id>0) $where.=" and t.u_id=$u_id";
if ($is_ass) $where.=" and t.add_u_id=".$_SESSION['u_id']; #show only tasks assigned by me to others
$page=get_page_option('page', $tbl_name."_lastpage");
$pagenum=get_page_option('pagenum', $tbl_name."_pagenum");
if (!$pagenum) $pagenum=$MAX_PAGE_ITEMS;
$page_offset=$page*$pagenum;
//********** sorting
#!!!TODO - add TREE view
$sortby=get_page_option('sortby', $tbl_name."_sortby", 'str');
if (!$sortby) $sortby='prio';
$ordsql=$SORTSQL[$sortby];
//**********
$search_str=$_REQUEST['s'];
# $sid=get_page_option('sid', $tbl_name."_sid",'');
# $sname=get_page_option('sname', $tbl_name."_sname",'');
# $sdesc=get_page_option('sdesc', $tbl_name."_sdesc",'');
$sid=$_REQUEST['sid']+0;
$sname=$_REQUEST['sname']+0;
$sdesc=$_REQUEST['sdesc']+0;
if (!$sid && !$sname && !$sdesc) $sname=1;
if ($search_str){
$ssql='';
if ($sid) $ssql.=(($ssql)?' or ':'')."t.t_id=".dbq(trim($search_str));
if ($sname) $ssql.=(($ssql)?' or ':'')."t.iname like ".dbq("%$search_str%");
if ($sdesc) $ssql.=(($ssql)?' or ':'')."t.idesc like ".dbq("%$search_str%");
if ($ssql) $where.=" and ($ssql)";
$moreurl.=(($moreurl)?'&':'').'s='.urlencode($search_str);
if ($sid) $moreurl.=(($moreurl)?'&':'').'sid=1';
if ($sname) $moreurl.=(($moreurl)?'&':'').'sname=1';
if ($sdesc) $moreurl.=(($moreurl)?'&':'').'sdesc=1';
}
//get list of items
$sql="select SQL_CALC_FOUND_ROWS t.*, p.iname prio_id_name, tus.is_read, tus.is_flagged
from ( $tbl_name t
LEFT OUTER JOIN prio p ON (p.prio_id=t.prio_id and p.status<>127) )
LEFT OUTER JOIN tu_status tus ON (tus.t_id=t.t_id and tus.u_id=".dbq($_SESSION['u_id']).")
where $where
and (t.is_private=0 or t.is_private=1 and t.u_id=".dbq($_SESSION['u_id'])." )
order by $ordsql
LIMIT $page_offset, $pagenum
";
$rows=db_array($sql);
$total_items=db_value("SELECT FOUND_ROWS()");
foreach($rows as $k => $row){
$tr_class='';
$tr_class.=($row['status']>=20)?' done_status':''; #gray out done status
$tr_class.=(!$row['is_read'])?' unread_status':''; #gray out done status
$rows[$k]=array_merge($row,array(
'iname' => str2cut($row['iname'],64),
'p_id_name' => db_value("select iname from project where p_id=".$row['p_id']),
'perc_compl_graph' => perc2graph($row['perc_compl']),
'u_id_name' => get_user_name($row['u_id']),
'start_time_human' => SQLDate2Str($row['start_time'],1),
'end_time_actual_human' => SQLDate2Str($row['end_time_actual'],1),
'add_time_human' => SQLDate2Str($row['add_time'],1),
'filter_itype' => $itype,
'filter_u_id' => $u_id,
'filter_p_id' => $p_id,
'filter_status' => $status,
'logged_access_level' => $_SESSION['access_level'],
'tr_class' => $tr_class,
));
}
$list_nav='';
if ($total_items>$pagenum){
// $total_pages=ceil($total_items/$pagenum);
$list_nav=make_List_Navigation($page, $total_items, $pagenum, "$this_script?".$moreurl."&page=", '', 'showall');
# $list_nav=make_List_Navigation2($page, $total_items, $pagenum, "$this_script?".$moreurl."&page=");
}
$ps=array(
'item_datarow' => $rows,
'item_datarow_ctr' => count($rows),
'list_navigation' => $list_nav,
//filters
'is_my' => $is_my,
'is_ass' => $is_ass,
'search_str' => $search_str,
'sortby' => $sortby,
'pagenum' => $pagenum,
'itype' => $itype,
'filter_p_id' => $p_id,
'filter_u_id' => $u_id,
'filter_status' => $status,
'filter_sid' => $sid,
'filter_sname' => $sname,
'filter_sdesc' => $sdesc,
'p_id_select'=> get_combo_select_sql("select p_id, iname from project where status<>127 order by iname", $p_id),
'u_id_select'=> get_combo_select_sql("select u_id, CONCAT(fname, ' ', lname) from users where status<>127 order by fname, lname", $u_id),
);
$ps=array_merge($ps, get_userinfo());
parse_page($GLOBALS['this_tpl_dir']."/list", $GLOBALS['PAGE_TPL_ADMIN'], $ps);
}
//******* do action with checkboxed items
function save_item_list(){
global $tbl_name, $tbl_key, $is_my, $is_ass;
$cbses=$_REQUEST['cb'];
foreach($cbses as $item_id => $value){
if (!$item_id) continue;
// $hITEM=get_quotes($item_id);
$IFORM=array(
'status' => 127,
);
$sql="update $tbl_name set ".get_sqlupdate_set($IFORM).", upd_time=now(), upd_u_id=".$_SESSION['u_id']." where $tbl_key=$item_id";
// rw($sql);
db_query($sql);
}
show_item_list();
}
//***************************
//if $forceform=1 - redisplay values from FORM, not DB
function show_one_item($forceform=0){
global $task_vars, $is_my, $is_ass;
global $item_id, $tbl_name, $tbl_key, $rowcolor;
$hITEMDB=array();
if ($_REQUEST['is_refresh']) $forceform=1;
$itype=get_page_option('itype', $tbl_name."_itype",'str');
$hITEM=$_REQUEST['item'];
if (!$hITEM){ //if not set - this is initial form call - we can make here initializations
$hITEM['itype']= ($itype)?$itype:$_SESSION['task_last_itype'];
# if ($is_my) $hITEM['u_id']=$_SESSION['u_id'];
$hITEM['p_id']=$_SESSION['task_last_p_id'];
}
$item_id=$_REQUEST['id']+0;
$hITEM[$tbl_key]=$item_id;
if ($item_id){ #edit mode
$hITEMDB=get_task($item_id);
}
if ($forceform){
$hITEM=array_merge($hITEMDB,$hITEM); //if redisplay from the FORM - merge with DB record, so read-only fields will be displayed too
}else{
if ($item_id){//only if Edit mode
$hITEM=&$hITEMDB; //making $hITEM same as $hITEMDB (no array copy)
}
}
//****************** COMMENTS
if ($item_id>0 && $hITEM['comm_ctr']>0){
$sql="select c.* , u.fname, u.lname
from comm c LEFT OUTER JOIN users u ON (u.u_id=c.add_u_id and u.status<>127)
where c.status<>127
and c.t_id=$item_id
order by c.add_time
";
$comm_datarow=db_array($sql);
foreach($comm_datarow as $k => $row){
$rowcolor=array_reverse($rowcolor);
$att_dr=get_att_list_dr('', $item_id, $row['comm_id']);
$comm_datarow[$k]=array_merge($row,array(
'idesc' => format_comm($row['idesc']), #!!!TODO add more comprehensive formatting with link emboss
'tr_class' => $rowcolor[0],
'u_id_name' => $row['fname'].' '.$row['lname'],
'att_list_comm_dr'=> $att_dr,
'att_list_comm_dr_ctr'=> count($att_dr),
'add_time_human' => SQLDate2Str($row['add_time'],1,'hms'),
));
}
}
//****************** COMMENTS END
mark_task_read($item_id);
$ps=array(
'is_my' => $is_my,
'is_ass' => $is_ass,
'itype' => $itype,
'is_adv_show'=> $_REQUEST['is_adv_show']+0,
'select_p_id' => get_combo_select_sql("select p_id, LEFT(iname,64) from project where status<>127 order by iname", $hITEM['p_id']),
'select_parent_t_id' => get_combo_tree_sql("select t_id, parent_t_id, LEFT(iname,64) from task where status<>127 and p_id=".dbq($hITEM['p_id'])." and t_id<>$item_id order by parent_t_id, iname", $hITEM['parent_t_id']),
'select_prio_id' => get_combo_select_sql("select prio_id, iname from prio where status<>127 order by sort_order", $hITEM['prio_id']),
'select_u_id' => get_combo_select_sql("select u_id, CONCAT(fname, ' ', lname) from users where status<>127 order by fname, lname", $hITEM['u_id']),
'start_time_input' => date2htmlInput_jq("item[start_time]", $hITEM['start_time']),
'end_time_input' => date2htmlInput_jq("item[end_time]", $hITEM['end_time']),
'end_time2_input' => date2htmlInput_jq("item[end_time2]", $hITEM['end_time2']),
'add_u_id_name' => ($hITEM['add_u_id'])?get_user_name($hITEM['add_u_id']):'',
'upd_u_id_name' => ($hITEM['upd_u_id'])?get_user_name($hITEM['upd_u_id']):'',
//attachments
'comm_datarow_ctr' => count($comm_datarow),
'comm_datarow' => $comm_datarow,
'att_list_dr' => get_att_list_dr('', $item_id, 0),
);
$ps=array_merge($ps, $hITEM);
$ps=array_merge($ps, get_userinfo());
parse_page($GLOBALS['this_tpl_dir']."/edit", $GLOBALS['PAGE_TPL_ADMIN'], $ps);
}
//*************************** save item info
function save_one_item(){
global $task_vars, $att_vars, $is_my, $is_ass;
global $tbl_name, $tbl_key, $tbl_fields;
$item_id=$_REQUEST['id']+0;
$RAW=$_REQUEST['item'];
if (validate_item($item_id, $RAW)){
$hITEM=get_task($item_id);
//read from form only necessary/allowed fields
$IFORM=form2dbhash($RAW, "$tbl_fields");
$_SESSION['task_last_p_id']=$IFORM['p_id'];
$_SESSION['task_last_itype']=$RAW['itype']+0;
//make some adjustments
$IFORM['start_time']=StrDate2SQL($IFORM['start_time']);
$IFORM['end_time']=StrDate2SQL($IFORM['end_time']);
$IFORM['end_time2']=StrDate2SQL($IFORM['end_time2']);
# $IFORM['end_time_actual']=StrDate2SQL($IFORM['end_time_actual']);
if (!$IFORM['start_time']) $IFORM['start_time']='~!NULL';
if (!$IFORM['end_time']) $IFORM['end_time']='~!NULL';
if (!$IFORM['end_time2']) $IFORM['end_time2']='~!NULL';
# if (!$IFORM['end_time_actual']) $IFORM['end_time_actual']='~!NULL';
//******************* process status/end_time_actual
if ($IFORM['status']!=$hITEM['status'] && $IFORM['status']==40){ #if status changed to CLOSED - set actual time
$IFORM['end_time_actual']=Unix2SQLDate(time());
}
if ($IFORM['status']!=$hITEM['status'] && $IFORM['status']<40){ #if status changed less that closed - clear actual time
$IFORM['end_time_actual']='~!NULL';
}
if ($item_id){ //id exists - update record
$IFORM['upd_u_id']=$_SESSION['u_id'];
$sql="update $tbl_name set ".get_sqlupdate_set($IFORM).", upd_time=now() where $tbl_key=$item_id";
// rw($sql);
db_query($sql);
check_task_changes($IFORM, $hITEM);
$GLOBALS['green_msg']=lng("Record has been modified");
} else { //id not exits - insert record
$IFORM['add_u_id']=$_SESSION['u_id'];
$IFORM['itype']=$RAW['itype']+0;
$sql="insert into $tbl_name ".get_sqlinsert_set($IFORM,', add_time',', now()');
// logger($sql);
$sth=db_query($sql);
$item_id=get_identity();
$IFORM['t_id']=$item_id;
#add comments record
add_task2comm($IFORM);
#send notification to all related users
send_task_new($IFORM['u_id'], $IFORM);
$GLOBALS['green_msg']=lng("New Record has been added");
}
$_REQUEST['id']=$item_id;
$p_id=$IFORM['p_id']+0;
$t_id=$item_id;
$comm_id=0;
# print_r($_FILES);
$upload_error=0;
$upload_ok=0;
foreach($_FILES as $field_name => $hUP){
# for($i=1;$i<=$GLOBALS['MAX_ATTACHMENTS'];$i++){ //upload attachments one by one
$path_parts=pathinfo( strtolower($hUP['name']) ); #get the extension
$att_id=add_att($p_id, $t_id, $comm_id, $path_parts['basename']);
//****** perform upload attached file (if present)
$res=upload_file($att_id, $field_name,
array(), //all extensions allowed
$att_vars['upload_path'],
array(
# 'preview' => 1,
# 'preview_maxw' => $GLOBALS['MAX_PREVIEW_IMG_WIDTH'],
# 'preview_maxh' => $GLOBALS['MAX_PREVIEW_IMG_HEIGHT'],
# 'resize' => 1,
# 'resize_maxw' => $GLOBALS['MAX_FULL_IMG_WIDTH'],
# 'resize_maxh' => $GLOBALS['MAX_FULL_IMG_HEIGHT'],
));
if ($res<0){ #error - upload failed
//$res==-2 - $att_id is empty, i.e. file is not provided, just skip this
if ($res!=-2){
$upload_error++;
}
}elseif($res>0){ #upload successfull
add_ok_att($att_id, $path_parts['extension']); //mark uploaded as successfull
$upload_ok++;
// $_REQUEST['is_rand']=1;
}else{ #no file specified (empty upload)
}
}
# //update att_size
# if ($upload_ok){
# $fsize=db_value("select sum(fsize) from att where t_id=$item_id and status=0");
# db_query("update task set att_size=".dbq($fsize)." where t_id=$item_id");
# }
if ($upload_error) $GLOBALS['err_msg']=lng("Some attachments wasn't uploaded properly");
//****** upload end
if ($_REQUEST['AndAddNext']){
unset($_REQUEST['item']);
unset($_REQUEST['id']);
}
show_one_item();
} else {
show_one_item(1);
}
}
//################# Validate item form values in IFORM
function validate_item($item_id=0, $IFORM){
global $task_vars, $err_msg, $is_my, $is_ass;
$REQFLD=array(
'p_id' => lng('Project'),
'iname' => lng('Title'),
'u_id' => lng('Assigned to'),
);
// if (!$item_id) $REQFLD['xxx']=lng('xxx'); //add validation only for Edit mode
//VALIDATE REQUIRED FIELDS
if (!$err_msg) { $err_msg=validate_form($IFORM, $REQFLD); }
//VALIDATE if field unique
# if (!$err_msg && is_dbrecord_exists2($GLOBALS['tbl_name'], 'email', $IFORM['email'], " and ".$GLOBALS['tbl_key']."<>$item_id and status<>127") ){
# $err_msg=lng("Such Email already exists. Please, select another.");
# }
if ($err_msg) { return 0 ;}
return 1;
}
//************************
function delete_item(){
global $is_my;
$item_id=$_REQUEST['id']+0;
if ( check_access_task($item_id)>=40 ){ #del
delete_task($item_id);
}
show_item_list();
}
//************* remove uploaded image
function delete_attach(){
global $task_vars;
global $att_vars;
global $is_my;
$t_id=$_REQUEST['id']+0;
$item_id=$_REQUEST['att_id']+0;
if ( check_access_att($item_id)>=40 ){
delete_att($item_id, 0, $t_id);
}
show_one_item();
}
//************* remove uploaded image
function delete_attach_comm(){
global $task_vars;
global $att_vars;
global $is_my;
$comm_id=$_REQUEST['id']+0;
$t_id=$_REQUEST['t_id']+0;
$item_id=$_REQUEST['att_id']+0;
if ( check_access_att($item_id)>40 ){
delete_att($item_id, $comm_id, $t_id);
}
show_one_item();
}
//*************************** save item info
function save_comm_item(){
global $comm_vars, $att_vars, $site_templ;
global $is_my;
$RAW=$_REQUEST['item'];
if ($RAW['t_id']){
$hT=get_task($RAW['t_id']+0);
$RAW['p_id']=$hT['p_id']+0;
}
if (validate_comm($item_id, $RAW)){
//read from form only necessary/allowed fields
$IFORM=form2dbhash($RAW, "p_id t_id idesc");
if ($item_id){ //id exists - update record
/*NO EDIT, JUST ADD
$IFORM['upd_u_id']=$_SESSION['u_id'];
$sql="update $tbl_name set ".get_sqlupdate_set($IFORM).", upd_time=now() where $tbl_key=$item_id";
// logger($sql);
db_query($sql);
$GLOBALS['green_msg']=lng("Record has been modified");
*/
} else { //id not exits - insert record
$IFORM['add_u_id']=$_SESSION['u_id'];
//change project status
$IFORM2=form2dbhash($RAW, "status");
if (strlen($IFORM2['status']) && $hT['t_id']>0 && $IFORM2['status']!=$hT['status']){
$status_name_old=get_select_name("$site_templ/common/sel/status.sel", $hT['status']);
$status_name_new=get_select_name("$site_templ/common/sel/status.sel", $IFORM2['status']);
db_query("update task set status=".dbq($IFORM2['status'])." where t_id=".dbq($hT['t_id']) );
$IFORM['idesc'].='<br><br><small>'.lng('Task status changed from').' <i>'.$status_name_old.'</i> '.lng('to').' <i>'.$status_name_new.'</i></small>';
}
$sql="insert into comm ".get_sqlinsert_set($IFORM,', add_time',', now()');
// logger($sql);
$sth=db_query($sql);
$item_id=get_identity();
//add cached counter
add_task_comm_ctr($IFORM['t_id']);
#send notification to all related users
send_comm_new($item_id);
$GLOBALS['green_msg']=lng("New Record has been added");
}
$_REQUEST['id']=$item_id;
$p_id=$IFORM['p_id']+0;
$t_id=$IFORM['t_id']+0;
$comm_id=$item_id;
$upload_error=0;
$upload_ok=0;
foreach($_FILES as $field_name => $hUP){
$path_parts=pathinfo( strtolower($hUP['name']) ); #get the extension
$att_id=add_att($p_id, $t_id, $comm_id, $path_parts['basename']);
//****** perform upload attached file (if present)
$res=upload_file($att_id, $field_name,
array(), //all extensions allowed
$att_vars['upload_path'],
array(
'preview' => 1,
# 'preview_maxw' => $GLOBALS['MAX_PREVIEW_IMG_WIDTH'],
# 'preview_maxh' => $GLOBALS['MAX_PREVIEW_IMG_HEIGHT'],
# 'resize' => 1,
# 'resize_maxw' => $GLOBALS['MAX_FULL_IMG_WIDTH'],
# 'resize_maxh' => $GLOBALS['MAX_FULL_IMG_HEIGHT'],
));
if ($res<0){ #error - upload failed
//$res==-2 - $att_id is empty, i.e. file is not provided, just skip this
if ($res!=-2){
$upload_error++;
}
}elseif($res>0){ #upload successfull
add_ok_att($att_id, $path_parts['extension']); //mark uploaded as successfull
$upload_ok++;
// $_REQUEST['is_rand']=1;
}else{ #no file specified (empty upload)
}
}
# //update att_size
if ($upload_ok){
$fsize=db_value("select sum(fsize) from att where t_id=$t_id and comm_id=$item_id and status=0");
db_query("update comm set att_size=".dbq($fsize)." where t_id=$t_id and comm_id=$item_id");
}
if ($upload_error) $GLOBALS['err_msg']=lng("Some attachments wasn't uploaded properly");
//****** upload end
if ($_REQUEST['AndAddNext']){
unset($_REQUEST['id']);
}
unset($_REQUEST['item']);
do_redirect("/php/task.php?Edit=1&id=".$t_id);
} else {
unset($_REQUEST['item']);
show_one_item();
}
}
//################# Validate item form values in IFORM
function validate_comm($item_id=0, $IFORM){
global $comm_vars, $err_msg;
global $is_my;
$REQFLD=array(
'idesc' => lng('Comment/Note'),
);
// if (!$item_id) $REQFLD['xxx']=lng('xxx'); //add validation only for Edit mode
//VALIDATE REQUIRED FIELDS
if (!$err_msg) { $err_msg=validate_form($IFORM, $REQFLD); }
if (!$err_msg && check_access_comm($item_id, $IFORM['t_id'], $IFORM['p_id'])<20 ){
$err_msg=lng("You cannot post comments for this Project/Task");
}
if (!$err_msg && !$IFORM['p_id']) {
$err_msg=lng("No Project defined");
}
//VALIDATE if field unique
# if (!$err_msg && is_dbrecord_exists2($GLOBALS['tbl_name'], 'email', $IFORM['email'], " and ".$GLOBALS['tbl_key']."<>$item_id and status<>127") ){
# $err_msg=lng("Such Email already exists. Please, select another.");
# }
if ($err_msg) { return 0 ;}
return 1;
}
function goto_item(){
global $tbl_name, $SORTSQL;
$dir=0;
$cmp='';
$name='';
$order_dir='';
$item_id=$_REQUEST['id']+0;
if (!$item_id){
show_one_item();
exit;
}
if ($_REQUEST['GoPrev']){
$dir=-1;
$cmp='<';
$name='Previous';
$order_dir='desc';
}elseif ($_REQUEST['GoNext']){
$dir=1;
$cmp='>';
$name='Next';
$order_dir='';
}else{
show_one_item();
exit;
}
#compute prev/next item according to SESSION status and SORTBY and project and assigned to
$hT=get_task($item_id);
$where='';
$status=get_page_option('status', $tbl_name."_status",'str');
$st_sql='';
if (strlen($status)) $where=" and t.status=$status ";
$itype=get_page_option('itype', $tbl_name."_itype",'str');
if (strlen($itype)) $where.=" and t.itype=".dbq($itype);
$p_id=get_page_option('p_id', $tbl_name."_p_id");
if ($p_id>0) $where.=" and t.p_id=$p_id";
$u_id=get_page_option('u_id', $tbl_name."_u_id");
# if ($is_my) $u_id=$_SESSION['u_id']; #!!!TODO - decide if to limit or not employee's view
if ($u_id>0) $where.=" and t.u_id=$u_id";
if ($is_ass) $where.=" and t.add_u_id=".$_SESSION['u_id']; #show only tasks assigned by me to others
/*
$sortby=get_page_option('sortby', $tbl_name."_sortby", 'str');
if (!$sortby) $sortby='prio';
$ordsql=$SORTSQL[$sortby];
*/
$sql="select t.t_id
from task t LEFT OUTER JOIN prio p ON (p.prio_id=t.prio_id and p.status<>127)
where t.t_id $cmp $item_id
and t.status<>127
$st_sql
order by t_id $order_dir
LIMIT 1
";
# rw($sql);
$t_id=db_value($sql);
if ($t_id){
$GLOBALS['item_id']=$t_id;
$_REQUEST['id']=$t_id;
}else{
$GLOBALS['err_msg']=lng("No $name item exists.");
}
show_one_item();
}
//***********************
function ajax_mark_task_flag(){
global $item_id;
$flag=$_REQUEST['flag']+0;
$err_msg='';
$status=0;
if ( !mark_task_flag($item_id, $flag) ){
$err_msg=lng('Error during flagging a record');
$status=1;
}
$ps=array(
'status' => php2js($status),
'err_msg' => php2js($err_msg),
);
parse_page($GLOBALS['this_tpl_dir']."/list", 'json.html', $ps);
}
?>