Source

com_prof3tablog / admin / admin.prof3tablog.html.php

Full commit
<?php

/** ensure this file is being included by a parent file */
defined( '_JEXEC' ) or die( 'Restricted access' );

class prof3tablogScreens {
   
	function view() {

		// Connect to the DB
		$db =& JFactory::getDBO();

		// Select all the Projects
		$query = "SELECT * FROM #__prof3ta_blog_articles";
		$db->setQuery( $query, 0);

		// ... And print them!

		// Table is not empty
		if ($articles = $db->loadObjectList()) {
			foreach ($articles as $article) {
				echo $article->title."<br />";
			}
		} else {
			echo "No articles in the database.<br />";
		}

	}

	function addForm() {

		echo "<form id=\"addForm\" name=\"addForm\" method=\"post\" action=\"index.php?option=com_prof3tablog&task=add\">";
		echo "<table>";
		echo "<tr><td>Title:<td/><td><input name=\"articleTitle\" type=\"text\" id=\"articleTitle\" /></td></tr>";
		echo "<tr><td>Text:<td/><td>
		<textarea name=\"articleText\" rows=20></textarea>
		</td></tr>";
		echo "<tr><td>Date (YYYY-MM-DD):<td/><td><input name=\"articleDate\" type=\"text\" id=\"articleDate\" /></td></tr>";
		echo "</table>";
		echo "<input type=\"submit\" name=\"Submit\" value=\"Add\" /><br />";
		echo "</form>";

	}

	function add() {

		// Connect to the DB
		$db =& JFactory::getDBO();

		$articleTitle = "'" . $db->getEscaped(JRequest::getVar('articleTitle')) . "'";
		$articleText = "'" . addslashes(JRequest::getVar('articleText','','POST','STRING',JREQUEST_ALLOWRAW)) . "'";
		$articleDate = "'" . $db->getEscaped(JRequest::getVar('articleDate')) . "'";

		$query = "INSERT INTO `#__prof3ta_blog_articles` VALUES ('',".$articleTitle.", ".$articleText.", ". $articleDate .");";
		$db->setQuery($query, 0);
		$db->query();
		echo "Article succesfully inserted!<br />";

	}

	function edit() {

		// Connect to the DB
		$db =& JFactory::getDBO();

		$articleTitle = "'" . $db->getEscaped(JRequest::getVar('articleTitle')) . "'";
		$articleId = "'" . $db->getEscaped(JRequest::getVar('articleId')) . "'";
		$articleText = "'" . addslashes(JRequest::getVar('articleText','','POST','STRING',JREQUEST_ALLOWRAW)) . "'";
		$articleDate = "'" . $db->getEscaped(JRequest::getVar('articleDate')) . "'";

		$updateQuery = "UPDATE #__prof3ta_blog_articles SET title = ". $articleTitle .", text=".$articleText.", date=".$articleDate." WHERE id = ". $articleId .";";

		$db->setQuery( $updateQuery );
		$db->query();
		echo JText::_('Article Details edited succesfully.');

	}

	function editChoose() {

		// Connect to the DB
		$db =& JFactory::getDBO();

		// Select all the Projects
		$query = "SELECT * FROM #__prof3ta_blog_articles";
		$db->setQuery( $query, 0);

		// ... And print them!

		// Table is not empty
		if ($articles = $db->loadObjectList()) {
			JText::_('Select the article:<br/>');
			echo "<form id=\"editChooseForm\" name=\"editChooseForm\" method=\"post\" action=\"index.php?option=com_prof3tablog&task=edit\">";
			foreach ($articles as $article) {
				echo "<INPUT TYPE='radio' NAME='articleId' VALUE='".$article->id."'> ";
				echo $article->title."<br />";
			}
			echo "<br/>";
			echo "<input type=\"submit\" name=\"Submit\" value=\"Go\" />";
			echo "</form>";
		} else {
			echo "No articles in the database.<br />";
		}

	}

	function editForm() {

		// Connect to the DB
		$db =& JFactory::getDBO();

		$articleId = $db->getEscaped(JRequest::getVar('articleId'));

		$query = "SELECT * FROM #__prof3ta_blog_articles WHERE id=".$articleId."";
		$db->setQuery( $query, 0);

		// ... And print them!

		// Table is not empty
		if ($article = $db->loadObject()) {
			$articleTitle = $article->title;
			$articleText = $article->text;
			$articleDate = $article->date;

		echo "<form id=\"editForm\" name=\"editForm\" method=\"post\" action=\"index.php?option=com_prof3tablog&task=edit\">";
		echo "<table>";
		echo "<tr><td>Title:<td/><td><input name=\"articleTitle\" type=\"text\" id=\"articleTitle\" value=\"".$articleTitle."\"/></td></tr>";
		echo "<tr><td>Text:<td/><td>
		<textarea name=\"articleText\" rows=20 \">".$articleText."</textarea>
		</td></tr>";
		echo "<tr><td>Date:<td/><td><input name=\"articleDate\" type=\"text\" id=\"articleDate\" value=\"".$articleDate."\"/></td></tr>";
		echo "</table>";
		echo "<input type='hidden' id='articleId' name='articleId' value='".$articleId."'> ";
		echo "<input type=\"submit\" name=\"Submit\" value=\"Edit\" /><br />";
		echo "</form>";

		} else {
			JText::_('Error');
		}

	}

	function delete() {

		// Connect to the DB
		$db =& JFactory::getDBO();

		$articleId = "'" . $db->getEscaped(JRequest::getVar('articleId')) . "'";

		$query = "DELETE FROM `#__prof3ta_blog_articles` WHERE id=".$articleId.";";
		$db->setQuery($query, 0);
		$db->query();
		echo "Article succesfully deleted!<br />";

	}

	function deleteChoose() {

		// Connect to the DB
		$db =& JFactory::getDBO();

		// Select all the Articles
		$query = "SELECT * FROM #__prof3ta_blog_articles";
		$db->setQuery( $query, 0);

		// ... And print them!

		// Table is not empty
		if ($articles = $db->loadObjectList()) {
			JText::_('Select the article:<br/>');
			echo "<form id=\"deleteChooseForm\" name=\"deleteChooseForm\" method=\"post\" action=\"index.php?option=com_prof3tablog&task=delete\">";
			foreach ($articles as $article) {
				echo "<INPUT TYPE='radio' NAME='articleId' VALUE='".$article->id."'> ";
				echo $article->title."<br />";
			}
			echo "<input type=\"submit\" name=\"Submit\" value=\"Go\" />";
			echo "</form>";
		} else {
			echo "No articles in the database.<br />";
		}

	}

}
?>