2016-06-01 2 views
0

Я делаю форму ошибки отчета для завода, но я застрял в правильной настройке радиокнопки, поскольку они должны быть динамическими, потому что данные собираются из файла csv. Файл CSV выглядит следующим образом:Как сделать динамические переключатели из файла csv с надлежащим формированием?

Issue Type,Issue Description,Issue ID,Machine 
Program Issue,Incorrect sheet size for program,1,EM Machines 
Program Issue,Incorrect sheet thickness for program,2,EM Machines 
Program Issue,Burst and tapping is on end of program,3,EM Machines 
Program Issue,Part not tooled ,4,EM Machines 
Program Issue,Part falling out of sheet,5,EM Machines 
Program Issue,Micro join too big on part,6,EM Machines 
Program Issue,Tooled part bursting but not tapping,7,EM Machines 
Program Issue,Uneven QTY of parts that have a left and right on sheet,8,EM Machines 
Program Issue,Excessive QTY on sheet,9,EM Machines 
Program Issue,Incorrect 'C' station selected,10,EM Machines 
Program Issue,No drawing attached to file,11,EM Machines 
Machine Issues,Blunt tool,12,EM Machines 
Machine Issues,Damaged tool,13,EM Machines 
Program Issue,No drawing attached to file,14,Pressbrake 
Program Issue,No overall length indicated in drawing,15,Pressbrake 

только данные Я действительно использованием в данный момент является описание выпуска и машины. Причина, по которой я использую эти два значения, состоит в том, что, когда пользователь нажимает на определенную кнопку «Сообщить об ошибке», им будут предоставлены уникальные параметры, поскольку машины на заводе, как правило, имеют разные ошибки. Все это рассматривается в функции. Вот эта функция:

function customErr ($ID) 
{ 
    $html = ""; 
    $issueReport_folder = 'document/Production System/'; 
    $issueReporting = $issueReport_folder.'IssueReporting.csv'; 

    $file_handle = fopen($issueReporting, "r"); 
    /*while (!feof($file_handle)) 
    { 
     $line_of_text = fgetcsv($file_handle, 1024); 
     $line_of_text[0]." ".$line_of_text[1]." ".$line_of_text[2]." ".$line_of_text[3]."<br>"; 
    }*/ 

    if ($ID == 20) 
    { 
     while (!feof($file_handle)) 
     { 
      $line_of_text = fgetcsv($file_handle, 1024); 
      if ($line_of_text[3] == "EM Machines") 
      {  
       $html .= $line_of_text[1]; 
      } 
     } 
    } 
    if ($ID == 30) 
    { 
     while (!feof($file_handle)) 
     { 
      $line_of_text = fgetcsv($file_handle, 1024); 
      if ($line_of_text[3] == "Pressbrake") 
      { 
       $html .= $line_of_text[1]; 
      } 
     } 
    } 
    fclose($file_handle); 
    return $html; 
} 

Основная проблема, с которой я сталкиваюсь, заключается в том, что я не могу получить параметры ошибки, чтобы попасть под название категории. Достаточно написать кнопки радио HTML легко ...

<label> 
<input name="category" 
type="radio" 
value="<?php echo $html; ?>"> 
<?php echo $html; ?> 
</label><br><br><br> 

... внутри функции, однако это означает, что все переключатели будут находиться в верхней части формы, а не под «категории» титул ,

На изображении ниже показано, как выглядит форма и где должны быть радиокнопки. Очевидно, что в полной версии радиокнопки будут иметь все значения.

enter image description here

Я слышал предложения, используя массив, однако я не совсем уверен, как осуществить это. Я также попытался вызвать функцию, однако она либо не возвращается должным образом, либо просто не работает.

Вот мой полный код, если вы хотите (HTML в нижней части):

<!DOCTYPE HTML> 
<html> 
<head> 
<link rel="stylesheet" type="text/css" href="/css/main_style.css"> 
<style> 
.error {color: #FF0000;} 
table, th, td {border: 1px solid white;} 
</style> 
</head> 
<body> 
<script> 
function close_window() { 
    close(); 
} 
</script> 
<?php 
error_reporting(E_ALL); 
ini_set('display_errors', '1'); 
include("includes/classes.php"); 
include("includes/classes_monitoring.php"); 
$link = open_v8_db(); 
$users = get_clocked_in_users(); 
$OperationID = @$_REQUEST['OperationID']; 

$title = ""; 
$grayedOut = false; 
$disabledInput = ""; 
$hiddenJobDiv = ""; 
$hiddenPartDiv = ""; 
$ID = ""; 
$html = ""; 

$jobid = @$_REQUEST['JobID']; 
$part_id = @$_REQUEST['PartID']; 
$machCode = @$_REQUEST['Machine']; 

if ($OperationID == 20) 
{ 
    customErr($OperationID); 
    $title = "Punching Machine"; 
    $grayedOut = true; 
} 
elseif ($OperationID == 30) 
{ 
    customErr($OperationID); 
    $title = "Folding Machine"; 
    $grayedOut = true; 
} 
elseif ($OperationID == 40 || $OperationID == 140) 
{ 
    $title = "Powder Coating"; 
    $grayedOut = true; 
} 
elseif ($OperationID == 50 || $OperationID == 150) 
{ 
    $title = "Assembly"; 
    $grayedOut = true; 
} 
elseif ($OperationID == 60 || $OperationID == 160) 
{ 
    $title = "Inspection"; 
    $grayedOut = true; 
} 
elseif ($jobid != "" && $part_id == "") 
{ 
    $title = "Job"; 
} 
else 
{ 
    $title = "General"; 
    $grayedOut = false; 
} 

if ($greyedOut = true) 
{ 
    $disabledInput = "readonly"; 
} 

function customErr ($ID) 
{ 
    $html = ""; 
    $issueReport_folder = 'document/Production System/'; 
    $issueReporting = $issueReport_folder.'IssueReporting.csv'; 

    $file_handle = fopen($issueReporting, "r"); 
    /*while (!feof($file_handle)) 
    { 
     $line_of_text = fgetcsv($file_handle, 1024); 
     $line_of_text[0]." ".$line_of_text[1]." ".$line_of_text[2]." ".$line_of_text[3]."<br>"; 
    }*/ 

    if ($ID == 20) 
    { 
     while (!feof($file_handle)) 
     { 
      $line_of_text = fgetcsv($file_handle, 1024); 
      if ($line_of_text[3] == "EM Machines") 
      {  
       $html .= $line_of_text[1]; 
      } 
     } 
    } 
    if ($ID == 30) 
    { 
     while (!feof($file_handle)) 
     { 
      $line_of_text = fgetcsv($file_handle, 1024); 
      if ($line_of_text[3] == "Pressbrake") 
      { 
       $html .= $line_of_text[1]; 
      } 
     } 
    } 
    fclose($file_handle); 
    return $html; 
} 

$jobErr = $partErr = $machErr = ""; 
$job = $part = $mach = $note = ""; 

if ($jobid == "") 
{ 
    $hiddenJobDiv = "style=\"display:none;"; 
} 
if ($part_id == "") 
{ 
    $hiddenPartDiv = "style=\"display:none;"; 
} 

function test_input($data) 
{ 
    $data = trim($data); 
    $data = stripslashes($data); 
    $data = htmlspecialchars($data); 
    return $data; 
} 
?> 
<div class="reportForm"> 
    <h2>Report <u><?php echo $title; ?></u> Error</h2> 
    <form action="send_form_email.php?OperationID=<?php print ($OperationID) ?>&title=<?php print ($title) ?>" method="post"> 
     <table> 
     <tr> 
      <td>Name:</td> 
       <td> 
       <select name="users"> 
       <?php 
       foreach($users as $key => $value){ 
        echo "<option value=\"$key\">$key</option>"; 
       } 
       ?> 
       </select> 
       </td> 
     </tr> 
     <tr> 
      <td <?php print $hiddenJobDiv ?>>Job Number:</td> <td><input type="text" name="jobid" value="<?php print ($jobid) ?>" <?php print $disabledInput ?>></td> 
     </tr> 
     <tr> 
      <td <?php print $hiddenPartDiv ?>>Part Number:</td> <td><input type="text" name="partid" value="<?php print ($part_id) ?>" <?php print $disabledInput ?>></td> 
     </tr> 
      <?php if ($OperationID == 20){ ?> 
      <tr> 
       <td>Machine:</td> <td><input type="text" name="mach" value="<?php print ($machCode) ?>" <?php print $disabledInput ?>></td> 
      <tr> 
      <?php } ?> 
     </table><br> 
     Category:<br><br><br> 
     <?php 
     $html .= customErr($ID); 
     ?> 
     <label> 
     <input name="category" 
     type="radio" 
     value="<?php echo $html; ?>"> 
     <?php echo $html; ?> 
     </label><br><br><br> 
     <?php 
     /* 
         ?> 
         <label> 
         <input name="category" 
         type="radio" 
         value="<?php echo $line_of_text[1]; ?>"> 
         <?php echo $line_of_text[1]; ?> 
         </label><br><br><br> 
         <?php 
     */ 
     ?> 
      <label> 
      <input name="category" type="radio" value="Other" checked>Other 
      </label><br><br><br> 
     Note:<br> <textarea name="comment" rows="10" cols="70" placeholder="More detail... (Is there a way to recreate the error? What happened?)"></textarea> 
     <br><br> 
     <input type="submit" name="submit" value="Submit" class="userFriendly"> 
     <a href="#" onclick="close_window();return false;"><input type="submit" name="close" value="Close" class="userFriendly"></a> 
    </form> 
</div> 
</body> 
</html> 

Резюме: Что мне нужно будет иметь файл CSV для печати под названием «Категория» в радио-кнопки форма.

Заранее спасибо.

ответ

1

Функция customErr($ID):

function customErr($ID) 
{ 
    $html = ""; 
    $issueReport_folder = 'document/Production System/'; 
    $issueReporting = $issueReport_folder.'IssueReporting.csv'; 

    $file_handle = fopen($issueReporting, "r"); 
    /*while (!feof($file_handle)) 
    { 
     $line_of_text = fgetcsv($file_handle, 1024); 
     $line_of_text[0]." ".$line_of_text[1]." ".$line_of_text[2]." ".$line_of_text[3]."<br>"; 
    }*/ 

    if ($ID == 20) 
    { 
     while (!feof($file_handle)) 
     { 
      $line_of_text = fgetcsv($file_handle, 1024); 
      if ($line_of_text[3] == "EM Machines") 
      { 
       $html[] = $line_of_text[1]; 
      } 
     } 
    } 
    if ($ID == 30) 
    { 
     while (!feof($file_handle)) 
     { 
      $line_of_text = fgetcsv($file_handle, 1024); 
      if ($line_of_text[3] == "Pressbrake") 
      { 
       $html[] = $line_of_text[1]; 
      } 
     } 
    } 
    fclose($file_handle); 
    return $html; 
} 

И выход категория будет:

Category:<br><br><br> 
     <?php 
     $html = customErr($OperationID); 
     foreach ($html as $oneError):?> 
     <label> 
      <input name="category" 
        type="radio" 
        value="<?php echo $oneError; ?>"> 
      <?php echo $oneError; ?> 
     </label><br> 
     <?endforeach;?> 
     <label> 
      <input name="category" type="radio" value="Other" checked>Other 
     </label><br><br><br> 

Окончательная форма будет выглядеть так: (если Choise $OperationID == 20 (пробивая), например,) enter image description here

или если ваш Choise $OperationID == 30 (Folding машина)

enter image description here

+0

Благодаря dumkaaa. Не на моем компьютере с файлами на данный момент. Выглядит многообещающе. Я знаю, как это происходит. – Moms

+0

Работает фантастически. Большое спасибо. – Moms

Смежные вопросы