All pastes #371164 Raw Edit

details

public text v1 · immutable
#371164 ·published 2007-02-25 03:55 UTC
rendered paste body
<?php
/*
 *    -----------------------------------------------------------------------
 *    Copyright (c) 2006 ibcnet - All Rights Reserved. 
 *    Author: Csenteri Zoltan; csenteri_zoltan@ibcnet.ro
 *    Modified by:
 *    $Id$
 *    -----------------------------------------------------------------------
 */
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

$permission = $fs->online_permission_view($my->id,$_GET['id']);
if($permission == 0 || $_SESSION['admin'] == 1)
{
	//check if the item id is integer
	if (ereg("^[0-9]+$", $_GET['id']))
	{	
		$item_exists = $fs->dbQuery( "SELECT summary FROM #__th_item WHERE item_id = '{$_GET['id']}'" );

	if ( $fs->dbCountRows( $item_exists ) ) {
    global $mosConfig_live_site,$mosConfig_list_limit;
        
    $item_details = $fs->GetTaskDetails( $_GET['id'] );
   
    $project_pref = $fs->dbQuery( "SELECT pp.* FROM #__th_project_options pp,
	#__th_item t WHERE pp.project_id = '" . $item_details['project_id'] . "' and pp.project_id = t.project_id
	and pp.user_id='$my->id' and t.item_id ='{$_GET['id']}'" );
  
    
    $permissions = $fs->dbFetchArray( $project_pref );
    $_SESSION['can_open_jobs']     = $permissions['view'];
    $_SESSION['can_modify_jobs']   = $permissions['modify'];
    $_SESSION['can_add_comments']  = $permissions['add_comment'];
    $_SESSION['can_attach_files']  = $permissions['add_attachment'];
    $_SESSION['can_item_close']    = $permissions['close'];
    $_SESSION['can_item_delete']   = $permissions['delete'];
    

    /*$project_pref = $fs->dbQuery( "SELECT pp.modify, pp.close,pp.delete FROM #__th_project_options pp,
	#__th_item t WHERE pp.project_id = '" . $item_details['project_id'] . "' and pp.project_id = t.project_id
	and pp.user_id='$my->id' and t.item_id ='{$_GET['id']}'" );

    $project_permissions = $fs->dbFetchArray( $project_pref );
    $can_item_modify = $project_permissions['modify'];
    $can_item_close  = $project_permissions['close'];
    $can_item_delete = $project_permissions['delete'];
    */
    
    if ( $item_details['item_creator_id'] == 0 ) {
        $summary = _DI_ANONYM_ITEM_FROM . ":" . $item_details['anonym_email'] . "";
    } else {
    	      
        $summary = stripslashes( $item_details['summary'] ); 
        
    }

    $detailed_desc = str_replace( "&", "&amp;", $item_details['detailed_desc'] );
    $detailed_desc = str_replace( "<br>", "\n", $detailed_desc );
    $detailed_desc = stripslashes( $detailed_desc );
        
    //////////////////////          EDIT ITEM   //////////////////////////////
    if ( ( $_SESSION['can_modify_jobs'] == '1') && $item_details['status'] < '100' && $_GET['edit'] == 'yep' ) {
	       require_once(  'edit_item_html.php' );
	       editItem($item_details, $summary,$detailed_desc,$fs);
    	//////////////////////          VIEW ITEM   //////////////////////////////
    } elseif ( $_SESSION['can_modify_jobs'] != '1' OR $item_details['status'] >= '100' OR !$GET['edit'] ) {
        require_once(  'details_item_html.php' );   
    	$timelogtype_sql = "SELECT * FROM #__th_timelog_type order by type_id";
    	$database->setQuery($timelogtype_sql);
		$tl_rows = $database->loadObjectList(); 
		$item_id = $item_details['item_id'];
		
		$query = "SELECT l.log_id,i.item_id,l.status FROM #__th_time_log l,#__th_item i
		WHERE l.user_id='$my->id' and l.status!='2'  and l.task_id=i.item_id";
		//echo "$query";
		$database->setQuery($query);
		$openedtimelog_rows = $database->loadObjectList(); 
	
			
		$query = "SELECT l.* FROM #__th_time_log l
		WHERE l.task_id = '".$item_id."' and l.user_id=$my->id and status!='2'";
        $database->setQuery($query);
		$timelog_rows = $database->loadObjectList(); 

		$query =  "SELECT user_id FROM #__th_item_resources WHERE item_id = '$item_id'"; 
		$database->setQuery($query);
		$res_rows = $database->loadObjectList(); 
				 
        viewItem($item_details, $summary,$tl_rows,$timelog_rows,$res_rows,$openedtimelog_rows,$fs);
   

    // End of checking if a job should be editable
    global $database;
    
    if ( $_GET['area'] ) {
    	$area = $_GET['area'];
	} else {
    	$area = 'comments';
	} ;
    
	$item_id = $item_details['item_id'];
	
    switch ($area)
    {
    	case "comments":
    		{
    			  			
			//if ( (($_SESSION['admin'] == "1") || $_SESSION['can_add_comments'] == "1")  &&  $item_details['status'] < '100' ) {

				require_once(  'comment_area.php' );
				$query = "SELECT c.*,u.name,loc.gmt_diff, loc.dst FROM #__th_comments c,#__users u 
				LEFT JOIN #__th_user_location loc ON ( u.id = loc.user_id ) 
				WHERE item_id = '$item_id' and c.user_id=u.id order by c.date_added DESC";
				 
				$database->setQuery($query);
				$rows = $database->loadObjectList();   
							
				commentArea($rows,$fs,$item_details['item_creator_id'],$item_details['customer_id'],$item_details['status_id'],$item_details['urgency_id']);
			   // } ;    			
    		}
	    	break;
    	case "attachments":
    		{
    			require_once(  'attachment_area.php' );
				$query = "SELECT a.*,u.name FROM #__th_attachments a,#__users u WHERE item_id = '$item_id' and a.added_by=u.id order by attachment_id DESC" ;
				$database->setQuery($query);
				$rows = $database->loadObjectList();   
				attachmentArea($rows,$fs,$item_details['status']);
    		}
    		break;	
    	
    	case "timelog":
    		{
    			$timelogtype_sql = "SELECT * FROM #__th_timelog_type order by type_id";
    			$database->setQuery($timelogtype_sql);
				$tl_rows = $database->loadObjectList();   
				              
				
			    $my_options = $fs->_getCookie( "thopper" );
			    
				if ( isset($my_options)) {
					$data = explode( "|", $my_options );
				   	$opt_line_per_page = $data[4];
				}	

				if ( is_numeric( $_GET['pagenum'] ) ) {
				    $pagenum = $_GET['pagenum'];
				} else {
				    $pagenum = "0";
				} ;
				
				if ( is_numeric( $_GET['perpage'] ) ) {
				    $perpage = $_GET['perpage'];
				} else {
				  if(isset($opt_line_per_page)) $perpage = $opt_line_per_page;
				  else $perpage = "20";
				} ;			
				
				$offset = $perpage * $pagenum;///		ORDER BY $orderby $sort*/
    			$query = "SELECT l.*,u.username,tt.type_name FROM #__th_time_log l,#__users u,#__th_timelog_type tt 
				WHERE l.task_id = '$item_id' and l.type=tt.type_id and l.user_id=u.id ORDER by log_id 
          		LIMIT $offset,$perpage";
    			
    			$database->setQuery($query);
				$rows = $database->loadObjectList();   
				
				$query = "SELECT task_id FROM #__th_time_log WHERE task_id = '$item_id'";
				$database->setQuery($query);
				$total_rows = $database->loadObjectList();   
				$total = count( $total_rows );
					
				
				 $edit_log_id = $_GET['editlog_id'];
				 if(isset($edit_log_id))
					{
					$query = "SELECT * FROM #__th_time_log WHERE log_id = '$edit_log_id'";
					$database->setQuery($query);
				    $log_rows = $database->loadObjectList();   
					}
				
				$query =  "SELECT user_id FROM #__th_item_resources WHERE item_id = '$item_id'"; 
				$database->setQuery($query);
				$res_rows = $database->loadObjectList(); 
				
				$query = "SELECT l.log_id,i.item_id,i.summary FROM #__th_time_log l,#__th_item i
				WHERE l.user_id='$my->id' and l.status!='2' and l.task_id=i.item_id";
				$database->setQuery($query);
				$openedtimelog_rows = $database->loadObjectList(); 
				
    			require_once(  'timelog_area.php' );
				timelogArea($rows,$pagenum, $perpage,$total,$tl_rows,$log_rows,$res_rows,$item_id,$item_details['customer_id'],$item_details['project_id'],$item_details['details'],$openedtimelog_rows,$fs);
				//conclusion( $totalRows, $searchword_clean, $pageNav );
    		}
    	break;	
    	
    	case "itemres":
    		{
    			$query = "SELECT res.id as res_id,res.item_id,res.user_id,u.*,l.location,l.gmt_diff,l.dst FROM #__users u, #__th_item_resources res 
    			left join #__th_user_location l on (l.user_id = res.user_id)
				WHERE item_id = '{$item_details['item_id']}' and u.id=res.user_id";
				$database->setQuery($query);
				$rows = $database->loadObjectList();   
				
				if($my->usertype=='Editor' || $_SESSION['admin'] == '1')
  				{
				$query = "SELECT * FROM #__users WHERE block = '0'
	  			and id<>'".$item_details['customer_id']."' ORDER BY name ASC";
				$database->setQuery($query);
				$user_rows = $database->loadObjectList();   
  				}
				$customer_id = $item_details['customer_id'];
				
				$query = "SELECT id FROM #__th_item_resources
    			WHERE item_id = '{$item_details['item_id']}' and user_id='$my->id'";
				$database->setQuery($query);
				$res_rows = $database->loadObjectList();   
				$res_count = count($res_rows);
				
				if(($_SESSION['can_open_jobs'] == '1' || $customer_id=='0') && $customer_id!=$my->id && $res_count==0)
					$add_resource = true;
				else $add_resource = false;
								
				require_once(  'resource_area.php' );
				resourseArea($rows,$item_id,$user_rows,$customer_id,$add_resource);
    		}
    	break;
    	
    	///////////////////////////  comment area ///////////////////////
			case "editcomment":
			{
			     
			  	$database->setQuery("SELECT c.*, u.name FROM #__th_comments c, #__users u 
			    WHERE c.comment_id = '{$_GET['comment_id']}' and c.user_id=u.id");
				$rows = $database->loadObjectList(); 
				$numResults = count($rows);
    			for ($i=0, $n=$numResults; $i < $n; $i++) 
    			{
    				$row = $rows[$i];				
			        $formatted_date = date( "l, j M Y, g:ia", $row->date_added);
			
			        $comment_text = str_replace( "<br>", "\n", $row->comment_text );
			        $comment_text = stripslashes( $comment_text );
			    } ;
			
			    ?>
				<h3><?php echo _ADMIN_EDIT_COMMENT; ?></h3>
				<form action="<?php echo $baseurl; ?>" method="post">
				<input type="hidden" name="option" value="com_thopper">
				<table class="admin">
			  	<tr>
			    	<td class="adminlabel"><?php echo "{"._ADMIN_COMMENT_BY."} $row->name - $formatted_date"; ?></td>
				  </tr>
			  	<tr>
			    	<td class="admintext"> <textarea class="admintext" cols="50" rows="10" name="comment_text"><?php echo $comment_text; ?></textarea></td>
				</tr>
			  	<tr>
			    	<td class="admintext" align="center">
			    		<input type="hidden" name="task" value="modify_item">
			    		<input type="hidden" name="action" value="editcomment">
			    		<input type="hidden" name="item_id" value="<?php echo $_GET['id']; ?>">
					    <input type="hidden" name="comment_id" value="<?php echo $_GET['comment_id']; ?>">
					    <input class="adminbutton" type="submit" value="<?php echo _ADMIN_SAVE_COMMENT; ?>">
				    </td>
			  	</tr>
				</table>
				</form>
				
			<?php
			}break;
    }
    } 
} ;

 }//if item id is integer
 else{
 	echo "<br><table><tr><td class=\"maintext\">"._DI_WRONG_INPUT."</td></tr></table><br>"; 
 }
}else if($permission == '1'){
  echo "<br><table><tr><td class=\"maintext\">"._DI_MUST_LOGIN_TO_ACCESS."</td></tr></table><br>";
}else if($permission == '2'){
  echo "<br><table><tr><td class=\"maintext\">"._DI_WRONG_INPUT."</td></tr></table><br>"; 
}else if($permission == '3'){
  echo "<br><table><tr><td class=\"maintext\">"._DI_NO_ACCESS_TO_ITEM."</td></tr></table><br>"; 
}

?>