<?php
$jed=$jedID2;
//$leader_id_stat=11;
//$overseer_id_stat=12;
//$support_id_stat=19;
//$other_id_stat=20;
//$Leader="Leader";
//$Pastor_Support="Pastor Support";
//$Admin_Support="Admin Support";
//$Additional_Resource="Additional Resource";

 $bottomRepReset .="<font size=\"2\">Refresh List</font><br />
 <FORM  name=\"formcheck3\"  METHOD=\"POST\" ACTION=\"GoTool/$prog?token=$tok&log=$logged\">
                <input type=\"hidden\" name=\"agent\" value=\"$agent_id\" />
                  <input type=\"hidden\" name=\"lookD\" value=\"$survey_id \" />

               <input type=\"hidden\" name=\"gbad\" value=\"0\" size=\"40\" />
               <input type=\"hidden\" name=\"sbad\" value=\"0\" size=\"40\" />
               <input type=\"hidden\" name=\"gbadMod\" value=\"$gbadMod\"  />
               <input type=\"hidden\" name=\"survey_id\" value=\"$survey_idR\"  />
                <input type=\"hidden\" name=\"jedID2\" value=\"$jed\"  />
				<input name=\"button name0\" type=\"image\" src=\"GoTool/image/refresh.png\" align=\"center\" /></form> ";




  $display_status .="<option  value=1> Enabled</option><option  value=2> Disabled</option>";






$sq112ab="SELECT * FROM $table_name362 WHERE customer_group_id >8 ORDER BY name ASC ";
  $result112ab = @mysql_query($sq112ab,$connection) or die(mysql_error());
while ($row112ab = mysql_fetch_array($result112ab)) {
   $leader_id1=  $row112ab['customer_group_id'];
 $cgfirst_id=  $row112ab['name'];
 $last_id=  $row112ab['lastname'];
//$display_listCustGroup .=  "<option value=$leader_id1>$cgfirst_id </option>";

}

                                 //List of Surveys
//$sq112ab="SELECT * FROM $table_name36 where customer_group_id =$leader_id_stat OR customer_group_id =$overseer_id_stat ORDER BY lastname ASC ";
$sq112ab="SELECT * FROM $table_name81 ORDER BY name ASC ";
  $result112ab = @mysql_query($sq112ab,$connection) or die(mysql_error());
while ($row112ab = mysql_fetch_array($result112ab)) {
    $leader_id1=  $row112ab['survey_id'];
 $first_id=  $row112ab['name'];
 //$last_id=  $row112ab['lastname'];
  $display_listL .=  "<option value=$leader_id1>$first_id</option>";
  // $display_listCustGroup .=  "<option value=$leader_id1>$first_id </option>";
}


                                          //find the surveys listed for metric
      $sq112cb="SELECT * FROM $table_name405 Where group_id ='$survey_id' ORDER BY leader_id ";
  $result112cb = @mysql_query($sq112cb,$connection) or die(mysql_error());
while ($row112cb = mysql_fetch_array($result112cb)) {
      $leader_idz=  $row112cb['leader_id'];



$sq112ab="SELECT * FROM $table_name76 Where survey_id='$leader_idz' ORDER BY surveyQQ_id ASC ";
  $result112ab = @mysql_query($sq112ab,$connection) or die(mysql_error());
while ($row112ab = mysql_fetch_array($result112ab)) {
    $leader_id1=  $row112ab['surveyQQ_id'];
    $leader_id1N=  $row112ab['surveyQ_id'];
    $gi=$gi+1;
 $first_id=  $row112ab['question'];
// $last_id=  $row112ab['lastname'];
  $display_listL_A .=  "<option value=$leader_id1>$gi-$leader_id1N-$first_id</option>";        //sum1
   $display_listL_B .=  "<option value=$leader_id1>$gi-$leader_id1N-$first_id</option>";       //sum2
   $display_listO .=  "<option value=$leader_id1>$gi-$leader_id1N-$first_id</option>";          //sum3
   $display_listCustGroup .=  "<option value=$leader_id1>$gi-$leader_id1N-$first_id</option>";               //sum4
}
$gi=0;
     }




$sq112ab="SELECT * FROM $table_name404 Where dropdown_id='2' ORDER BY value ASC ";
  $result112ab = @mysql_query($sq112ab,$connection) or die(mysql_error());
while ($row112ab = mysql_fetch_array($result112ab)) {
    $leader_id1=  $row112ab['table_id'];
 $first_id=  $row112ab['value'];
 //$last_id=  $row112ab['lastname'];
  $display_listL_Adm .=  "<option value=$leader_id1>$first_id</option>";        //operation 1
        $display_listS .=  "<option value=$leader_id1>$first_id</option>";      //operation 2
}



//$sq112ab="SELECT * FROM $table_name36 where customer_group_id =$overseer_id_stat ORDER BY lastname ASC";
 // $result112ab = @mysql_query($sq112ab,$connection) or die(mysql_error());
//while ($row112ab = mysql_fetch_array($result112ab)) {
//    $leader_id1=  $row112ab['customer_id'];
// $first_id=  $row112ab['firstname'];
// $last_id=  $row112ab['lastname'];
 // $display_listO .=  "<option value=$leader_id1>$first_id $last_id</option>";

//}


//$sq112ab="SELECT * FROM $table_name36 ORDER BY lastname ASC";
//  $result112ab = @mysql_query($sq112ab,$connection) or die(mysql_error());
//while ($row112ab = mysql_fetch_array($result112ab)) {
//    $leader_id1=  $row112ab['customer_id'];
// $first_id=  $row112ab['firstname'];
// $last_id=  $row112ab['lastname'];
//  $display_listS .=  "<option value=$leader_id1>$first_id $last_id</option>";

//}

//$sq112ab="SELECT * FROM $table_name36 where customer_group_id =$other_id_stat ORDER BY lastname ASC";
$sq112ab="SELECT * FROM $table_name404 Where (table_id>'15'AND table_id<='20') Or table_id='25' Or dropdown_id='2'  ORDER BY value ASC";
  $result112ab = @mysql_query($sq112ab,$connection) or die(mysql_error());
while ($row112ab = mysql_fetch_array($result112ab)) {
    $leader_id1=  $row112ab['table_id'];
 $first_id=  $row112ab['value'];
$last_id=  $row112ab['lastname'];
  $display_listOth .=  "<option value=$leader_id1>$first_id $last_id</option>";

}




$sq112aaD ="SELECT * FROM $table_nameApp Where survey_id ='$survey_id' ";
 $result333D = @mysql_query($sq112aaD,$connection) or die(mysql_error());
  $num33 = mysql_num_rows($result333D);

  while ($row1D = mysql_fetch_array($result333D)) {
$survey_id=  $row1D['survey_id'];
  $Cname=   stripslashes($row1D['name']);
  $Ccomments=  stripslashes($row1D['comment']);

  
  $sq112aaE ="SELECT * FROM $table_name405 Where group_id ='$survey_id' ";
   $result333E = @mysql_query($sq112aaE,$connection) or die(mysql_error());
   while ($row1E = mysql_fetch_array($result333E)) {
  $leader_match_id=   $row1E['leader_match_id'];
  $leader_id=   $row1E['leader_id'];
$leader_idA=   $row1E['leader_idA'];
$leader_idB=   $row1E['leader_idB'];
$leader_idAdm=   $row1E['leader_idAdm'];
    $Cstatus=  ($row1E['status']);
  $Ccreate_date= $row1E['create_date'];
  
  $EditQ= $row1E['EditQ'];
  $EditA= $row1E['EditA'];

   $Cstatus2[1]="Enabled";
  $Cstatus2[0]="Disabled";
  
    $sql361 ="SELECT * FROM $table_name81 WHERE survey_id = '$leader_id' ";
        $result2261 = @mysql_query($sql361,$connection) or die(mysql_error());
        $row161 =mysql_fetch_array($result2261,MYSQL_ASSOC);

     if ($leader_id == $row161['survey_id'])
        {
          $Lfirst_id=  $row161['name'];
 //$Llast_id=  $row161['lastname'];

        }
else{
//$Llast_id='';
$Lfirst_id='';
}     


 $sql361 ="SELECT * FROM $table_name76 WHERE surveyQQ_id = '$leader_idA' ";
        $result2261 = @mysql_query($sql361,$connection) or die(mysql_error());
        $row161 =mysql_fetch_array($result2261,MYSQL_ASSOC);

     if ($leader_idA == $row161['surveyQQ_id'])
        {
          $Lfirst_idA=  $row161['question'];
// $Llast_idA=  $row161['lastname'];

        }else{
//$Llast_idA='';
$Lfirst_idA='';
}     


 $sql361 ="SELECT * FROM $table_name76 WHERE surveyQQ_id = '$leader_idB' ";
        $result2261 = @mysql_query($sql361,$connection) or die(mysql_error());
        $row161 =mysql_fetch_array($result2261,MYSQL_ASSOC);

     if ($leader_idB == $row161['surveyQQ_id'])
        {
          $Lfirst_idB=  $row161['question'];
 //$Llast_idB=  $row161['lastname'];

        }else{
//$Llast_idB='';
$Lfirst_idB='';
}     



 $sql361 ="SELECT * FROM $table_name404 WHERE table_id = '$leader_idAdm' ";
        $result2261 = @mysql_query($sql361,$connection) or die(mysql_error());
        $row161 =mysql_fetch_array($result2261,MYSQL_ASSOC);

     if ($leader_idAdm == $row161['table_id'])
        {
          $Lfirst_idAdm=  $row161['value'];
 //$Llast_idAdm=  $row161['lastname'];

        }else{
//$Llast_idAdm='';
$Lfirst_idAdm='';
}     



  
  
  $overseer_id= $row1E['overseer_id'];
  
      $sql361 ="SELECT * FROM $table_name76 WHERE surveyQQ_id = '$overseer_id' ";
        $result2261 = @mysql_query($sql361,$connection) or die(mysql_error());
        $row161 =mysql_fetch_array($result2261,MYSQL_ASSOC);

     if ($overseer_id == $row161['surveyQQ_id'])
        {
          $OLfirst_id=  $row161['question'];
 //$OLlast_id=  $row161['lastname'];

        }else{
//$OLlast_id='';
$OLfirst_id='';
}     

        
 $support_id= $row1E['support_id'];
  
      $sql361 ="SELECT * FROM $table_name404 WHERE table_id = '$support_id' ";
        $result2261 = @mysql_query($sql361,$connection) or die(mysql_error());
        $row161 =mysql_fetch_array($result2261,MYSQL_ASSOC);

     if ($support_id == $row161['table_id'])
        {
          $SLfirst_id=  $row161['value'];
 //$SLlast_id=  $row161['lastname'];

        }  else{
//$SLlast_id='';
$SLfirst_id='';
}     




  $other_id= $row1E['other_id'];

      $sql361 ="SELECT * FROM $table_name404 WHERE table_id = '$other_id' ";
        $result2261 = @mysql_query($sql361,$connection) or die(mysql_error());
        $row161 =mysql_fetch_array($result2261,MYSQL_ASSOC);

     if ($other_id == $row161['table_id'])
        {
          $OthLfirst_id=  $row161['value'];
$OthLlast_id=  $row161['lastname'];

        }else{
$OthLlast_id='';
$OthLfirst_id='';
}         
        
        
       $gother_id= $row1E['customer_group_id'];

      $sql361 ="SELECT * FROM $table_name76 WHERE surveyQQ_id = '$gother_id' ";
        $result2261 = @mysql_query($sql361,$connection) or die(mysql_error());
        $row161 =mysql_fetch_array($result2261,MYSQL_ASSOC);

     if ($gother_id == $row161['surveyQQ_id'])
        {
          $gOthLfirst_id=  $row161['question'];

        } else{
$gOthLfirst_id='';
}     
        
  
  

  $Ccreate_dateE= $row1E['create_date'];
 // }
  if ($Ccreate_date==$blink){
 // $Ccreate_date="<div class=warning>No leader records created for this group</div>";
  }
  
   $display_entry .="<FORM  name=\"formcheck$ag_id\"  METHOD=\"POST\" ACTION=\"GoTool/$prog?token=$tok&log=$logged\">
              <tr> <input type=\"hidden\" name=\"agent\" value=\"$agent_id\" />
                 <input type=\"hidden\" name=\"gbad\" value=\"1\"  />
                 <input type=\"hidden\" name=\"lookD\" value=\"$survey_id\"  />
                 <input type=\"hidden\" name=\"leader_match_id\" value=\"$leader_match_id\"  />
                <input type=\"hidden\" name=\"jedID2\" value=\"$jed\"  />
            <td style=\"text-align: center;\"><input type=\"checkbox\" name=\"boxman\" value=\"$survey_id\" />
                </td>
              <td>$survey_id-$leader_match_id</td>
               <td>$Ccreate_date</td>
              <td>$Cname</td>
              <td>$Ccomments</td>
              <td>
              <select size=1 name=leaderQ >
                  <option selected value=$leader_id>$Lfirst_id $Llast_id</option>
              <option value=0>None</option>
              $display_listL
                  </select>
              </td>


 <td>
              <select size=1 name=leaderQA >
                  <option selected value=$leader_idA>$Lfirst_idA $Llast_idA</option>
              <option value=0>None</option>
              $display_listL_A
                  </select>
              </td>



 <td>
              <select size=1 name=leaderQB >
                  <option selected value=$leader_idB>$Lfirst_idB $Llast_idB</option>
              <option value=0>None</option>
              $display_listL_B
                  </select>
              </td>



 <td>
              <select size=1 name=leaderQAdm >
                  <option selected value=$leader_idAdm>$Lfirst_idAdm $Llast_idAdm</option>
              <option value=0>None</option>
              $display_listL_Adm
                  </select>
              </td>



              <td>

               <select size=1 name=leaderO >
                  <option selected value=$overseer_id>$OLfirst_id $OLlast_id</option>
                  <option value=0>None</option>
                 $display_listO
                  </select>

              </td>
               <td>

               <select size=1 name=leaderS >
                  <option selected value=$support_id>$SLfirst_id $SLlast_id</option>
                  <option value=0>None</option>
                 $display_listS
                  </select>

              </td>
                             <td>

               <select size=1 name=leaderOth >
                  <option selected value=$other_id>$OthLfirst_id $OthLlast_id</option>
                  <option value=0>None</option>
                 $display_listOth
                  </select>

              </td>

              <td>

               <select size=1 name=custgroup >
                  <option selected value=$gother_id>$gOthLfirst_id</option>
                  <option value=0>None</option>
                  $display_listCustGroup
                  </select>

              </td>

               <td class=\"left\">$Cstatus2[$Cstatus]<br />
              <select size=1 name=\"statusP\">
              <option selected=\"selected\" value=$Cstatus>$Cstatus2[$Cstatus]</option> $display_status</select></td>

              <td>Select Update<input name=\"button name\" type=\"image\" src=\"GoTool/image/add.png\" /> </td>
                </tr></form>    ";

$gother_id='';
$other_id='';
$support_id='';
$overseer_id='';
$leader_idAdm='';
$leader_idA='';
$leader_idB='';
$leader_id='';

$OthLfirst_id='';
$OthLlast_id='';
 $gOthLfirst_id='';
 $SLfirst_id='';
 $SLlast_id ='';
 $OLfirst_id='';
 $OLlast_id='';
 $Lfirst_idAdm='';
 $Llast_idAdm='';
 $Lfirst_idB ='';
 $Llast_idB='';
 $Lfirst_idA='';
 $Llast_idA ='';
 $Lfirst_id='';
 $Llast_id='';

        }

   $display_entry .="
                <FORM  name=\"formcheck$ag_id\"  METHOD=\"POST\" ACTION=\"GoTool/$prog?token=$tok&log=$logged\">
              <tr> <input type=\"hidden\" name=\"agent\" value=\"$agent_id\" />
                 <input type=\"hidden\" name=\"gbad\" value=\"1005\"  />
                 <input type=\"hidden\" name=\"lookD\" value=\"$survey_id\"  />
                 <input type=\"hidden\" name=\"leader_match_id\" value=\"\"  />
                <input type=\"hidden\" name=\"jedID2\" value=\"$jed\"  />
            <td style=\"text-align: center;\"><input type=\"checkbox\" name=\"boxman\" value=\"$survey_id\" />
                </td>
              <td> </td>
               <td></td>
              <td>$Cname</td>
              <td>$Ccomments</td>
              <td>
              <select size=1 name=leaderQ1 >


                  <option value=0>None</option>
                 $display_listL
                  </select>
              </td>


 <td>
              <select size=1 name=leaderQA1 >


                  <option value=0>None</option>
                 $display_listL_A
                  </select>
              </td>


 <td>
              <select size=1 name=leaderQB1 >


                  <option value=0>None</option>
                 $display_listL_B
                  </select>
              </td>


 <td>
              <select size=1 name=leaderQAdm1 >


                  <option value=0>None</option>
                 $display_listL_Adm
                  </select>
              </td>



              <td>

               <select size=1 name=leaderO1 >


                  <option value=0>None</option>
                 $display_listO
                  </select>

              </td>
               <td>

               <select size=1 name=leaderS1 >

                  <option value=0>None</option>
                 $display_listS
                  </select>

              </td>
                             <td>

               <select size=1 name=leaderOth1 >

                  <option value=0>None</option>
                 $display_listOth
                  </select>

              </td>

              <td>

               <select size=1 name=custgroup1 >

                  <option value=0>None</option>
                  $display_listCustGroup
                  </select>

              </td>

               <td class=\"left\">$Cstatus2[$Cstatus]<br />
              <select size=1 name=\"statusP1\">
             $display_status</select></td>

              <td>Add Elements<input name=\"button name\" type=\"image\" src=\"GoTool/image/add.png\" /> </td>
                </tr></form>

                ";

 //$edit_block .="<div class=success2>Ability to Edit $Record: Status $Cstatus2D[$EditQD]<br>
   //             Ability to Edit Answers: Status $Cstatus2D[$EditAD]<br></div> ";

              }
             // <a href=\"$loc2/admin/index.php?route=sale/customer&amp;token=$tok\">Add Stakeholder: Customer, Leader, Support Person, etc.</a>  <br />

   $display_blockV .="

     $bottomRepReset<br/>

                Note: [Sum1 (Operation1) Sum2]  (operation2)  [Sum3 (operation3) Sum4]   <br/>
                ie:   [Sum1 difference Sum2] divisor [Sum3 multipy Sum4] = [Sum1-Sum2]/[Sum3 *Sum4]<br/>
                Use of a timeframe nullifies use of Sum4 Column.
                Count in Operation 1 Does not use the Sum2 column.
                Count in Operation 2 Does nothing.
                Count in Operation 3 Does not use Sum4.
        <table class=\"list\">
          <thead>
            <tr> Note: <i>Below: Sort Function  is Case-Sensitive. Date sort is Format-Sensitive. </i>
              <td width=\"1\" style=\"text-align: center;\"><input type=\"checkbox\" onclick=\"$('input[name*=\'selected\']').attr('checked', this.checked);\" /></td>
              <td class=\"filterable\"> $Record ID</a>
                </td>
              <td class=\"filterable\">  Date Added </td>
                            <td class=\"filterable\"> $Record Title</td>
              <td class=\"filterable\">$Record Summary</td>
              <td class=\"filterable\">$Leader</td>
<td class=\"filterable\">$Leader_A</td>
<td class=\"filterable\">$Leader_B</td>
<td class=\"filterable\">$Administrator</td>
              <td class=\"filterable\">$Pastor_Support</td>
              <td class=\"filterable\">$Admin_Support</td>
              <td class=\"filterable\">$Additional_Resource</td>
               <td class=\"filterable\">$Additional_Group</td>
              <td class=\"filterable\">Status</td>
                 <td class=\"right\">Action</td>

            </tr>
          </thead>
          <tbody>
            <tr class=\"filter\">
              <td></td>
              <td align=\"right\"><input type=\"text\" name=\"filter_order_id\" value=\"\" size=\"4\" onkeyup=\"Table.filter(this,this)\"/></td>
              <td><input type=\"text\" name=\"filter_date_added\" value=\"\" size=\"12\" class=\"filter\" onkeyup=\"Table.filter(this,this)\" /></td>
              <td><input type=\"text\" name=\"filter_title\"  value=\"\"  onkeyup=\"Table.filter(this,this)\" /></td>
            <td><input type=\"text\" name=\"filter_summary\" value=\"\"  onkeyup=\"Table.filter(this,this)\" /></td>
            <td><input type=\"text\" name=\"filter_leader\" value=\"\"  onkeyup=\"Table.filter(this,this)\" /></td>
     <td><input type=\"text\" name=\"filter_title\"  value=\"\"  onkeyup=\"Table.filter(this,this)\" /></td>
            <td><input type=\"text\" name=\"filter_summary\" value=\"\"  onkeyup=\"Table.filter(this,this)\" /></td>
            <td><input type=\"text\" name=\"filter_leader\" value=\"\"  onkeyup=\"Table.filter(this,this)\" /></td>
            <td><input type=\"text\" name=\"filter_pastor\" value=\"\"  onkeyup=\"Table.filter(this,this)\" /></td>
              <td><input type=\"text\" name=\"filter_support\" value=\"\"  onkeyup=\"Table.filter(this,this)\" /></td>
                <td><input type=\"text\" name=\"filter_resource\" value=\"\"  onkeyup=\"Table.filter(this,this)\" /></td>
                 <td><input type=\"text\" name=\"filter_addgroup\" value=\"\"  onkeyup=\"Table.filter(this,this)\" /></td>
              <td><input type=\"text\" name=\"filter_status\" value=\"\"  onkeyup=\"Table.filter(this,this)\" /></td>
              <td align=\"right\"></td>
            </tr>
                                    $display_entry


                                  </tbody>
        </table>
        <br />
        <br />
       $noteB <br />

      <div class=\"pagination\"><div class=\"results\">Showing Results: $num33 Record(s)";

           
              
              

?>
