<?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Capitalism Worldwide: News, views &amp; adventures from the world's #1 global activist network</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="styles.css" rel="stylesheet" type="text/css" />

<!-- keywords for search egines: -->
<meta name="Description" content="Capitalism Worldwide: News, views & adventures from the world's #1 global activist network " />
<meta name="Keywords" content="capitalism, activism" />
<meta name="URL" content="http://www.capitalismworldwide.org" />
<meta name="language" content="en" />
<meta name="author" content="Prodos Institute" />
<meta name="robots" content="ALL" />
<meta name="revisit-after" content="30 days" />
<meta name="document-rating" content="General" />
<meta name="document-state" content="Dynamic" />

</head>

<body bgcolor="#FFFFE6">

<table width="75%" height="75%" border="0">
  <tr bgcolor="#CC3366">
    <th height="55" colspan="2"><span class="title">Capitalism Worldwide</span><br />
        News, views &amp; adventures from the world's #1 global activist network
</th>
  </tr>
  <tr>
   
    <td width="90%" valign="top" bgcolor="#FFFFFF">
<h3><a href="backend.php">Add, edit, and delete articles</a> here. 
        <a href="index.php">View the site</a> you made.
        <?php


function  do_error($error) {

	echo  "<h2>Hmm, looks like there is a connection problem between the webpage and the database...<br \>";

	echo "The reported error was \"$error.\"\n<br \>";

	echo "Best you get hold of the <a href=\"mailto:errors@rationalmind.net\">site admin</a> and let him know.</h2><br \>";

	die;

}



if (!$db = @mysql_connect("www.rationalmind.net", "capworld", "capworld")) {

	$db_error = "Could not connect to MySQL Server";

	do_error($db_error);

}


// $db = mysql_connect("www.rationalmind.net", "capworld", "capworld");
// $db = mysql_connect("localhost", "root");
mysql_select_db("capworld",$db);

if ($submit) {
  // here if no id then adding else we're editing
//  $Title=addslashes($Title);

if ($form_data) {$data = addslashes(fread(fopen($form_data, "r"), filesize($form_data))); }

    
  if ($id) {
  
    $sql = "UPDATE articles SET id='$newid',DatePosted='$DatePosted',TimePosted='$TimePosted',Author='$Author',Subject='$Subject', Description='$Description',Title='$Title',Text='$Text',ImgURL='$ImgURL',ImgAltText='$ImgAltText', IntroText='$IntroText', Image='$data',ImgName='$form_data_name',imgsize='$form_data_size',imgtype='$form_data_type' WHERE id='$id'";


  } else {

	$sql = "INSERT INTO articles (id,DatePosted,TimePosted,Author,Subject,Description,Title,Text,ImgURL,ImgAltText,IntroText, Image, ImgName, imgsize, imgtype) VALUES ('$id','".date("Y-m-d")."','".date("H:i:s")."','$Author','$Subject','$Description','$Title','$Text','$ImgURL','$ImgAltText','$IntroText', '$data','$form_data_name','$form_data_size','$form_data_type')"; 

  }
  // run SQL against the DB

  $result = mysql_query($sql);

	echo "<p><h3>Record updated/edited!<br /><br />";
	printf("<a href=\"%s\">Go Back to Admin Page</a></h3></p>", $PHP_SELF);
	$id= mysql_insert_id();
	print "<p>This file has the following Database id: <b>$id</b>";

	
	
} elseif ($delete) {
	// delete a record
    $sql = "DELETE FROM articles WHERE id=$id";	
    $result = mysql_query($sql);
	echo "<p><h3>Record deleted!<br /><br />";
	printf("<a href=\"%s\">Go Back to Admin Page</a></h3></p>", $PHP_SELF);
	
	
} elseif ($deleteimg) {
	// delete a record
    $sql = "UPDATE articles SET Image=NULL, ImgName=NULL, imgsize=NULL, imgtype=NULL WHERE id=$deleteimg";
	$result = mysql_query($sql);
	echo "<p><h3>Image deleted!<br /><br />";
	printf("<a href=\"%s\">Go Back to Admin Page</a></h3></p>", $PHP_SELF);	
	
} else {
  // this part happens if we don't press submit
  if (!$id) {
    // print the list if there is not editing
    	echo "<h3>Select an article to edit or delete:</h3> \n";
		echo "<table><tr><th>id #</th><th>Click to Edit</th><th>DELETE!</th></tr>\n";
		echo "<span class=\"clickforfull\">\n";
		
	$result = mysql_query("SELECT id, DatePosted, Title FROM articles ORDER BY id",$db);
	while ($myrow = mysql_fetch_array($result)) {
		
		echo "<tr><td>\n";
		printf("%s", $myrow["id"]);
		echo "</td><td>\n";

		printf("<a href=\"%s?id=%s\">%s - %s</a> \n", $PHP_SELF, $myrow["id"], $myrow["DatePosted"], $myrow["Title"]);
		echo "</td><td>\n";
		printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a>", $PHP_SELF, $myrow["id"]);
		echo "</td><tr>\n";
	
    }
		echo "</table>\n";
		echo "</span>\n";
  }

  ?>
      </h3>
      <h3>(Update: Images are now stored in the database with each article, eliminating the need for uploading them to the server.)</h3>
      <p></p>
      <hr />
      <h3 align="center"><?php if ($id) { ?>Edit<?php  }else{ ?>Add a new <?php } ?> Article:</p></h3>
      <form method="post" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data">
        <?php

  if ($id) {
    // editing so select a record
    $sql = "SELECT * FROM articles WHERE id=$id";
    $result = mysql_query($sql);
    $myrow = mysql_fetch_array($result);
	
    $id = $myrow["id"];
    $DatePosted = $myrow["DatePosted"];
	$TimePosted = $myrow["TimePosted"];
	$Text = $myrow["Text"];
	$Subject = str_replace("\"", "&quot;", $myrow["Subject"]);
	$Author = str_replace("\"", "&quot;", $myrow["Author"]);
	$Title = str_replace("\"", "&quot;", $myrow["Title"]);
	$Description = $myrow["Description"];
	$ImgURL = $myrow["ImgURL"];
	$ImgAltText = $myrow["ImgAltText"];
	$IntroText = $myrow["IntroText"];
	$id = $myrow["id"];
	$imgtype = $myrow["imgtype"];
	

    

	
	
    // print the id for editing
?>
<input type="hidden" name="id" value="<?php echo $id ?>" />
        
<?php    }   ?>


        <table border="0">

		<?php IF ($id) { ?>
          <tr>
            <td>DatePosted:          
              </td>
            <td>


<input name="DatePosted" type="text" class="cooledit" value="<?php echo $DatePosted ?>" />
                      
TimePosted:          
              <input name="TimePosted" type="text" class="cooledit" value="<?php echo $TimePosted ?>" />
        </td>
          </tr>

			<?php } ?>     
          <tr>
            <td>Author:          
              
        </td>
            <td>
<input name="Author" type="text" class="cooledit" value="<?php echo $Author ?>" />
		<?php IF ($id) { ?>
			id:  <input name="newid" type="text" class="cooledit" value="<?php echo $id ?>" />
			<?php } ?>               
               </td>
          </tr>
          <tr>
            <td>Subject:          
              

        </td>
            <td>
<select name="Subject" class="cooledit">
                <option value="<?php echo $Subject ?>"><?php echo $Subject ?></option>
                <?php

	$result = mysql_query("SELECT * FROM subject",$db);
	  while ($myrow = mysql_fetch_array($result)) {
		printf("<option value=\"%s\">%s</option>",  $myrow["subject"],$myrow["subject"]);
	    }
?>
          </select></td>
          </tr>
          <tr>
            <td>Title:          
              </td>
            <td><input name="Title" type="text" class="cooledit" value="<?php echo $Title ?>" size="70" maxlength="255" /></td>
          </tr>
        </table>
        <p>
Opening Sentence:<br />
          <textarea name="IntroText" cols="80" rows="3" class="cooledit" id="IntroText"><?php echo $IntroText?></textarea>
          <br />
          Opening Paragraph::<br />
          <textarea name="Description" cols="80" rows="8" class="cooledit" id="Description"><?php echo $Description ?></textarea>
        <br />
        </p>
        <p>Text: (If you don't type any text, the &quot;click here for more&quot; link will not be shown.)<br />
          <textarea name="Text" cols="80" rows="22" class="cooledit"><?php echo $Text ?></textarea>
        <br />
        </p>
        <p><br />
		  <input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
    <br />
          Upload an Image to the Database<br />
          <input type="file" name="form_data"  size="40" class="cooledit" />		

		 
  </p>
        <?php 
if ($imgtype) { 
printf("The current image is: <img src=\"fetch.php?id=%s\"><br />\n", $id);
echo "Uploading another image will replace the current one.\n";
printf("<a href=\"%s?deleteimg=%s\">Delete this image.</a>", $PHP_SELF, $id);

 } ?>
         


        <p>OR, Refer to a URL: 
          <input type="text" name="ImgURL" value="<?php echo $ImgURL ?>" class="cooledit" />
        (If you want to upload the image yourself.)<br />
		<br />
          Specify the alt text:
<input type="text" name="ImgAltText" value="<?php echo $ImgAltText ?>" class="cooledit" />
		</p>
        <hr />
		 <input type="reset" name="reset" value="RESET Changes" class="cooledit"/>
          <input type="submit" name="submit" value="SUBMIT Changes" class="cooledit"/>

      </form>

<?php
}
?>
      
</td>


   
 <td width="10%" valign="top" bgcolor="#FFE4F2">
	
<?php include("sidebar.php") ?>
	</td>
  </tr>
</table>


<!-- visual editor -->

<script>QBPATH='editor'; VISUAL=0; FULLCTRL=1</script>
<script src="editor/quickbuild.js"></script>
<script src="editor/tabedit.js"></script>
<script src="editor/returnnl.js"></script>
<script src="editor/recover.js"></script>



</body>
</html>

