不同用户登录时的回显问题

时间:2011-06-06 03:11:43

标签: php session echo

我一直在尝试在其他用户登录时更改系统列表或表格页面的输出。


我有2个主要用户(管理员和超级管理员)和次要用户(公司注册帐户)。我的管理员使用的是上传其他公司发送的文件。然后将上传的文件传递给另一个帐户“super admin”。超级管理员用于批准或拒绝管理员提交的上传文件。这些文件最初来自其他公司。该表已按员工姓名,状态和职位排序。并且我已经插入了它应该回显名称和id一次的条件。

这是

之前的条件

当管理员登录时,家中的表将输出所有上传的文件,无论其状态如何。这也适用于超级管理员。而在另一家公司中,只能看到或输出该公司员工上传的文件。 所有这些代码都正常工作。

这是我期待的条件

当管理员登录时,主页中的表将输出所有上传的文件,无论其状态如何。当超级管理员登录时,主页表将仅输出状态为已批准且未批准的文件。上传的具有待处理状态的文件必须在我正在努力做的名为“新上传”的其他页面中回显。当其他用户登录时,他们只会看到具有已批准或未批准状态的文件。

我希望我能说清楚。 :(我一直试图解决这个问题2天,但总是出现错误的输出,所以我想请你帮忙:(


这是输出表在我的系统中的样子

if the admin page is login

*EmployeeID*     *EmployeeName*     *Title*     *FileDate*     *Status*     *Confirmation*

  20864125           Keisha          file2     Feb 01, 2000     Pending         Delete
  20080407           Mariel          file5     Aug 01, 2000     Pending         Delete
                                     file1     Jan 01, 2000     Pending         Delete
  16521253           Riorei          file13    Jan 01, 2000     Pending         Delete
                                     file10    Mar 20, 2003     Pending         Delete  

if the super admin login

*EmployeeID*     *EmployeeName*     *Title*     *FileDate*     *Status*           *Confirmation*

  20864125           Keisha          file2     Feb 01, 2000     Pending         Approve/Not Approve
  20080407           Mariel          file5     Aug 01, 2000     Pending         Approve/Not Approve
                                     file1     Jan 01, 2000     Pending         Approve/Not Approve
  16521253           Riorei          file13    Jan 01, 2000     Pending         Approve/Not Approve
                                     file10    Mar 20, 2003     Pending         Approve/Not Approve     

an if other user log in

*EmployeeID*     *EmployeeName*     *Title*     *FileDate*     *Status*           

  20864125           Keisha          file2     Feb 01, 2000     Pending         

现在您看到了差异,我想在该输出中应用新条件:(这是我使用的代码


while ($row = mysql_fetch_assoc($query))
                            {
                                $file_id = $row['file_id'];
                                $file_desc = $row['file_description'];
                                $file_date = $row['file_date'];
                                $file_name = $row['file_name'];
                                $file_accs = $row['folder_access'];
                                $file_employee  = $row['employee_id'];
                                $file_confir = $row['confirmation'];
                                $file_ename = ucwords($row['employee_name']);

                                $emp_id=$emp_id==$row['employee_id']?"":$row['employee_id'];
                                $emp_name=$emp_name==$row['employee_name']?"":$row['employee_name'];

                                $info = pathinfo($file_name);
                                $file_ext = $info['extension'];                                 



                                echo '<tr>
                                    <td>
                                        &nbsp; 
                                    </td>
                                    </tr>
                                    <tr class="subone">
                                    <td class="sub" width="100">
                                        '.$emp_id.'
                                        <br />
                                        &nbsp;
                                    </td>';
                                    if($_SESSION[$fgmembersite->GetLoginSessionVar()] == 'sa')
                                    {

                                    ?><td class="sub" width="100">
                                        <a href="" onclick = javascript:newPopup('addfile.php?emp=<?php echo $file_employee ?>');><?php echo$emp_name?></a>
                                        <br />
                                        &nbsp;
                                    </td><?php
                                    }
                                    else
                                        {
                                            echo '<td class="sub" width="182">
                                            '.$emp_name.' 
                                            <br />
                                            &nbsp;
                                            </td>';
                                        }


                                    echo'<td  class="sub" width="218">
                                        <a href="'.$file_accs.$file_name.'" target="_blank" style="text-decoration: underline;">'.$file_desc.'</a>
                                        <br />
                                        &nbsp;
                                    </td>
                                    <td  class="sub" width="100">
                                        '.date('M d, Y',mktime(0,0,0,substr($file_date,5,2),substr($file_date,8,2),substr($file_date,0,4))).'
                                        <br />
                                        &nbsp;
                                    </td>
                                    <td  class="sub" width="100">   
                                                '.$file_confir.'                
                                    <br />
                                            &nbsp;
                                            </td>';
                                    if($_SESSION[$fgmembersite->GetLoginSessionVar()] == 'sa')
                                    {
                                        if($file_confir == 'Pending' OR $file_confir == 'NotApproved')
                                        {                                               
                                            if(isset($_GET['id']))
                                            {
                                                $fgmembersite->Delete_Db($_GET['id']);
                                            }
                                                echo '<td  class="sub" width="100"> 
                                                <a href="index.php?id='.$file_id.'">Delete</a>
                                                <br />
                                                &nbsp;
                                                </td>';
                                        }
                                    }
                                    else if($_SESSION[$fgmembersite->GetLoginSessionVar()] == 'admin')
                                        {
                                            if($file_confir == 'Pending')
                                            {   
                                                    if(isset($_GET['yes']))
                                                    {
                                                        $fgmembersite->UpdateYesDB($_GET['yes']);
                                                        //echo "<script>location.reload();</script>";
                                                    }
                                                    else if(isset($_GET['no']))
                                                    {
                                                        $fgmembersite->UpdateNoDB($_GET['no']);
                                                        //echo "<script>location.reload();</script>";
                                                    }
                                                    if (!isset($_GET['offset'])) {
                                                        $prevoffset = 0;
                                                    } else {
                                                        $prevoffset = $_GET['offset'];
                                                    }                                                       
                                                    echo'<td  class="sub" width="100">  
                                                    <a href="index.php?offset='.$prevoffset.'&searchfile='.$search.'&namelist='.$listname.'&yes='.$file_id.'">Approve</a>                                           
                                                    <br /><br />

                                                    <a href="index.php?offset='.$prevoffset.'&searchfile='.$search.'&namelist='.$listname.'&no='.$file_id.'">NotApprove</a>                                     
                                                    &nbsp;
                                                    </td> ';
                                            }   
                                        }
                                    }?>

当新条件尚未应用时,此功能正常。现在我的问题是如何在这里应用新条件?我尝试过使用这组代码:

if($_SESSION[$fgmembersite->GetLoginSessionVar()] != 'sa' && $file_confir == '' OR $file_confir == 'NotApproved')
在echo语句之前

。但它产生了错误的输出,有人可以告诉我该怎么办? :(我知道我应该使用条件语句来做到这一点,但我不知道哪一个适合。感谢那些愿意回复。

1 个答案:

答案 0 :(得分:0)

你的if / elseif语句已经检查了admin和superadmin,普通用户不会只是在其他地方吗?

if($_SESSION[$fgmembersite->GetLoginSessionVar()] == 'sa'){
    // your code here
} elseif($_SESSION[$fgmembersite->GetLoginSessionVar()] == 'admin') {
    // more code here
} else {
    // here goes the code of your regular user
    if($file_confir == '' OR $file_confir == 'NotApproved'){
        // display the file 
    }
}

作为旁注:如果不混合HTML和PHP,您可能会发现编写代码/调试要容易得多。代码格式/缩进也不一致,但可能是由于复制/粘贴