<?PHP include("config.php");

if(!is_admin()) {
    header('Location:'.$site_url.'/');
    exit();
}

// Query to fetch non-validated roadshow events:
$results = mysql_query("SELECT * FROM ".$prefix.$main_table."Edits ORDER BY edit_timestamp ASC");

// check to see if set is empty
$none = FALSE;
if (mysql_num_rows($results) == 0) { $none = TRUE; }

// set the page title
$pagetitle = "Admin: ".$local_singular." Validation";

// set meta tags
$meta_keywords = "";
$meta_description = "";
?>

<? include("include_common_head.php"); ?>

<body class="listings">
  <? include($common_path . "/ads/ad_wallpaper.html"); ?>

  <div class="container">
    <? include($common_path . "/templates/include_header.php"); ?>
    <div class="main">
      <div class="contentwrapper clearfix">
        <? include("include_breadcrumb.php"); ?>

        <section class="section listings section-has-widgets section-static remove-sidebar">
          <div class="sidebar-b">
            <? include("include_sidebar.php"); ?>
          </div>

          <div class="content content-has-widgets">
            <div class="grid">
                <h1>Unvalidated Public Edits</h1>
                <form method="post" action="wiki_validate_X.php"  enctype="multipart/form-data">
                <? if ($none == TRUE) {
                    echo "<p>There are no edits waiting to be validated.</p>";
                } ?>

                  <div class="dtable form">
                    <? 
                    $x = 0;
                    while($row = mysql_fetch_array($results)){
                      $x++;
                      if($x % 2 == 0){ $bg = '#dddddd'; }else{ $bg = '#eeeeee'; }
                      
                      $arrEditors = mysql_fetch_array(mysql_query("SELECT user_username FROM ".$prefix."User WHERE user_id = ".$row[edit_user_id_fk]." LIMIT 1"));
                      
                      $editor_user_username = $arrEditors[user_username];
                      
                      $boolEditorIsOwner = false;
                      if ($row['edit_user_id_fk'] == $row[$field_lead.'submitted_by']) { $boolEditorIsOwner = true; }
                    ?>
                    <div class="drow">
                      <div class="dcell name">Name</div>
                      <div class="dcell divider"></div>
                      <div class="dcell value">
	                      <a href="<? echo "wiki_view.php?edit_id=$row[edit_id]"; ?>"><? echo $row[$field_lead.'name']; ?></a>
                      </div>
                    </div>
                    <div class="drow">
                      <div class="dcell name">Edited on</div>
                      <div class="dcell divider"></div>
                      <div class="dcell value">
	                      <? echo date("F j, Y", $row[edit_timestamp]); ?> by <? echo "<a href=\"http://forum.slowtwitch.com/gforum.cgi?username=".$editor_user_username.";\" target=\"_blank\">".$editor_user_username."</a>"; if ($boolEditorIsOwner) { echo " (original ".$local_singular_lc." submitter)"; } else { echo ""; } ?>
                      </div>
                    </div>
                    <div class="drow">
                      <div class="dcell name">Info</div>
                      <div class="dcell divider"></div>
                      <div class="dcell value">
                        <? 
                          if(strlen($row[$field_lead.'info']) > 400){
                            $phrase = "&hellip;";
                          }
                          else {
                            $phrase = "";
                          }
                            
                          echo substr(htmlspecialchars(strip_tags(stripslashes($row[$field_lead.'info']))), 0, 160)."&hellip;"; 
                          echo $phrase; 
                        ?>
                      </div>
                    </div>
                    <div class="drow">
                      <div class="dcell name">Location</div>
                      <div class="dcell divider"></div>
                      <div class="dcell value">
                          <? 
                            if(strlen($row[$field_lead.'info']) > 400){
                              $phrase = "&hellip;";
                            }
                            else{
                              $phrase = "";
                            }
                            
                            echo substr(htmlspecialchars(strip_tags(stripslashes($row[$field_lead.'info']))), 0, 160)."&hellip;"; 
                            echo $phrase; 
                          ?>
                      </div>
                    </div>
                    <div class="drow">
                      <div class="dcell name"></div>
                      <div class="dcell divider"></div>
                      <div class="dcell value">
                      	<input type="checkbox" value="<? echo($row[edit_id]); ?>" name="validate[]"> Validate this edit. <input type="checkbox" value="<? echo($row[edit_id]); ?>" name="delete[]"> Delete this edit.<br /></div></td></tr>
                      </div>
                    </div>
                    <? } ?>
                  </div>
                
                  <div class="btn-wrapper">
                    <input type="submit" value="Process Selected Roadshow Events" class="btn">
                  </div>
                </form>
            </div><!-- end grid -->
          </div><!-- end content -->
        </section>

      </div><!-- end contentwrapper -->
    </div> <!-- end main -->

  <? include($common_path . "/templates/include_footer.php") ?>
  </div> <!-- container  -->
</body>
<? include($common_path . "/templates/include_global_js.php") ?>
</html>