MyBB Community Forums

Full Version: Goals Page
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Below is a really simple script that'll allow you to have a goals page.
Currently, if the userid = 1, then 3 forms are shown, Add a Goal, Delete a Goal, and Update a Goal.
ALL GOALS MUST START WITH [(space)]

Demo Page

Go to Admin CP -> Templates & Styles -> Templates -> Your Theme -> Header Templates -> header
And add the follow line to link to the goals page.
<a href="{$mybb->settings['bburl']}/goals.php" class="popup_item">Goals</a>

For first time use, uncomment line 13-23, then re-comment the lines.

Make a new file and insert what's below.
Then upload to /forum
<?php
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////// This script is brought to you by LichTheMan of MyBB.com ///////////////////////////////////
/////// You may edit this script, but may NOT in any way, shape, or form distribute it while claiming it as yours ///////
/////////////////////////// If you have any questions or comments, feel free to contact me at: //////////////////////////
////////////////////////////////////////////////// [email protected] ///////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


define('IN_MYBB', 1); // (1a)
require "./global.php"; // (1b)

/*$db->query("CREATE TABLE IF NOT EXISTS ".TABLE_PREFIX."goals (
  goalid int NOT NULL AUTO_INCREMENT,
  ans int NOT NULL,
  goal varchar(100) NOT NULL,
  user varchar(30) NOT NULL,
  uid int NOT NULL,
  date_add varchar(50) NOT NULL,
  date_comp varchar(50) NOT NULL,
  PRIMARY KEY (goalid),
  UNIQUE (goal)
		)");*/
		
add_breadcrumb("Goals Page", "goals.php"); // (2)
eval("\$goals = \"".$templates->get("goals")."\";"); // (3)
output_page($goals); // (4)

if ($_GET['a'] == 'add') {
	if($mybb->user['uid'] != 1) {
		echo "You are not allowed to add any goals.<br />
			<a href='{$mybb->settings['bburl']}/goals.php'>View the current goals</a>.<br />";
	} else {
		$goal_add = $_POST['goal_add'];
		$user = $mybb->user['username'];
		$user = $mybb->user['uid'];
		$ans = $_POST['ans_add'];
		$date_add = date("D, M d-Y h:i:s A");
		if($ans == 1) {
			$date_comp = date("D, M d-Y h:i:s A");
			$goal = str_replace("[ ]", "[X]", $goal_add);
		} else {
			$date_comp = "N/A";
			$goal = $goal_add;
			$ans = 0;
		}
	
		$sql = "INSERT INTO ".TABLE_PREFIX."goals VALUES (0, '$ans', '$goal', '$user', '$uid', '$date_add', '$date_comp')";
		$result = $db->query($sql);

		if($goal == "" || $goals == null) {
			echo "Sorry, but please go <a href='{$mybb->settings['bburl']}/goals.php'>back</a> and enter a goal.";
		} else {
			if(!$result) {
				echo "Sorry, but there was an error with adding the goal.<br />";
				mysql_error();
			} else {
				echo "You added the goal: <br />
					<blockquote>Goal: " . $goal . "<br />
								Username: " . $user . "<br />
								Completed: " . $ans . "<br />
								Date Added: " . $date_add . "<br />
								Date Completed: " . $date_comp . "<br />
					</blockquote>
					(A 1 = Completed, a 0 = Not Completed)<br />
					<a href='{$mybb->settings['bburl']}/goals.php'>Add another goal or view the current goals</a>.<br />";
			}
		}
	}
} elseif ($_GET['a'] == 'delete') {
	if($mybb->user['uid'] != 1) {
		echo "You are not allowed to delete any goals.<br />
			<a href='{$mybb->settings['bburl']}/goals.php'>View the current goals</a>.<br />";
	} else {
		$goal = $_POST['goal_delete'];
	
		$sql = "DELETE FROM ".TABLE_PREFIX."goals WHERE goal = '$goal'";
		$result = $db->query($sql);
		
		if($goal == "" || $goals == null) {
			echo "Sorry, but please go <a href='{$mybb->settings['bburl']}/goals.php'>back</a> and enter a goal.";
		} else {
			if(!$result) {
				echo "Sorry, but there was an error with adding the goal.<br />";
				mysql_error();
			} else {
				echo "You Deleted the goal: <br />
					<blockquote>Goal: " . $goal . "<br />
					</blockquote>
					<a href='{$mybb->settings['bburl']}/goals.php'>Delete another goal or view the current goals</a>.<br />";
			}
		}
	}
} elseif ($_GET['a'] == 'update') {
	if($mybb->user['uid'] != 1) {
		echo "You are not allowed to update any goals.<br />
			<a href='{$mybb->settings['bburl']}/goals.php'>View the current goals</a>.<br />";
	} else {
		$goal_update = $_POST['goal_update'];
		$goal = str_replace("[ ]", "[X]", $goal_update);
		$ans = 1;
		$date_comp = date("D, M d-Y h:i:s A");
	
		$sql = "UPDATE ".TABLE_PREFIX."goals SET ans = '$ans', date_comp = '$date_comp', goal = '$goal' WHERE goal = '$goal_update'";
		$result = $db->query($sql);
	
		if($goal == "" || $goals == null) {
			echo "Sorry, but please go <a href='{$mybb->settings['bburl']}/goals.php'>back</a> and enter a goal.";
		} else {
			if(!$result) {
				echo "Sorry, but there was an error with adding the goal.<br />";
				mysql_error();
			} else {
				echo "You updated the goal: <br />
					<blockquote>Goal: " . $goal . "<br />
								Completed: " . $ans . "<br />
								Date Completed: " . $date_comp . "<br />
					</blockquote>
					(A 1 = Completed, a 0 = Not Completed)<br />
					<a href='{$mybb->settings['bburl']}/goals.php'>Update another goal or view the current goals</a>.<br />";
			}
		}
	}
} else {
	echo "	<td class='tcat'><span class='smalltext'><strong>Current Goals</strong></span></td>
		</tr>
		<tr>
			<td class='trow1'><span class='smalltext'>";
			if($mybb->user['uid'] == 1) {
				echo "You can use these forms to update the Goals database.<br />
					<fieldset>
						<legend>Add a Goal</legend>
						<form name='goal_add' action='{$mybb->settings['bburl']}/goals.php?a=add' method='post'>
							Goal Name: <input type='text' name='goal_add' /><br />
							Completed:<br />
							<input type='radio' name='ans_add' value='1' /> Yes &nbsp;&nbsp; <input type='radio' name='ans_add' value='0' /> No<br />
							(Must use [ ] at the beginning.)<br />
							(Eg. [ ] 100 Members)<br />
							<input type='submit' value='Submit' onClick='return check_goal_add();' />
						</form>
					</fieldset>
					
					<br />
					
					<fieldset>
						<legend>Delete a Goal</legend>
						<form name='goal_delete' action='{$mybb->settings['bburl']}/goals.php?a=delete' method='post'>
							Goal Name: <input type='text' name='goal_delete' /><br />
							(Must use [ ] at the beginning.)<br />
							(Eg. [ ] 100 Members)<br />
							<input type='submit' value='Submit' onClick='return check_goal_delete();' />
						</form>
					</fieldset>
					
					<br />
					
					<fieldset>
						<legend>Update a Goal</legend>
						<form name='goal_update' action='{$mybb->settings['bburl']}/goals.php?a=update' method='post'>
							Goal Name: <input type='text' name='goal_update' /><br />
							(Must use [ ] at the beginning.)<br />
							(Eg. [ ] 100 Members)<br />
							<input type='submit' value='Submit' onClick='return check_goal_update();' />
						</form>
					</fieldset>";
			}
			
			echo "</span>
				<br />
				<table width='100%'>
					<tr>
						<th>Goal ID</th>
						<th>Goal</th>
						<th>Added By</th>
						<th>Added</th>
						<th>Completed</th>
					</tr>";
					
			$query = $db->simple_select("goals",  "*", "1=1", array("order_by" => 'goalid'));
			while ($result = $db->fetch_array($query)) {
				$goalid = $result['goalid'];
				$goal = $result['goal'];
				$user = $result['user'];
				$uid = $result['uid'];
				$date_add = $result['date_add'];
				$date_comp = $result['date_comp'];
				
			$sql = "SELECT `uid` FROM `".TABLE_PREFIX."users` WHERE `username` = '$user' ";
				$result2 = $db->fetch_array($sql);
				$userid = $result2['uid'];
				
				echo "<tr>	
						<td>$goalid</td>
						<td>$goal</td>
						<td><a href='{$mybb->settings['bburl']}/member.php?action=profile&uid=$uid' target='_blank'>$user</a></td>
						<td>$date_add</td>
						<td>$date_comp</td>
					</tr>";
			}
			
			echo "</table>
				</td>";
}
echo "</tr>
	</table>
	{$footer}";
?>

To customize who can use the forms:
Replace:
$mybb->user['uid'] != 1
with the usergroup or userid's that you want to use it.
If you need help with this, post below who you want using it.

If you have any questions or comments, please post them in this thread.
not working properly
Since 448 is a non-standard http error code, hard to say what you have there - lol.

[attachment=43420]
(2020-10-28, 01:05 PM)PARADOXP Wrote: [ -> ]not working properly

Create a new goals.php page in your directory where index.php is located and add this code there



<?php
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////// This script is brought to you by LichTheMan of MyBB.com ///////////////////////////////////
/////// You may edit this script, but may NOT in any way, shape, or form distribute it while claiming it as yours ///////
/////////////////////////// If you have any questions or comments, feel free to contact me at: //////////////////////////
////////////////////////////////////////////////// [email protected] ///////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


define('IN_MYBB', 1); // (1a)
require "./global.php"; // (1b)

$db->query("CREATE TABLE IF NOT EXISTS ".TABLE_PREFIX."goals (
  goalid int NOT NULL AUTO_INCREMENT,
  ans int NOT NULL,
  goal varchar(100) NOT NULL,
  user varchar(30) NOT NULL,
  uid int NOT NULL,
  date_add varchar(50) NOT NULL,
  date_comp varchar(50) NOT NULL,
  PRIMARY KEY (goalid),
  UNIQUE (goal)
		)");
		
add_breadcrumb("Goals Page", "goals.php"); // (2)
eval("\$goals = \"".$templates->get("goals")."\";"); // (3)
output_page($goals); // (4)

if ($_GET['a'] == 'add') {
	if($mybb->user['uid'] != 4) {
		echo "You are not allowed to add any goals.<br />
			<a href='{$mybb->settings['bburl']}/goals.php'>View the current goals</a>.<br />";
	} else {
		$goal_add = $_POST['goal_add'];
		$user = $mybb->user['username'];
		$user = $mybb->user['uid'];
		$ans = $_POST['ans_add'];
		$date_add = date("D, M d-Y h:i:s A");
		if($ans == 1) {
			$date_comp = date("D, M d-Y h:i:s A");
			$goal = str_replace("[ ]", "[X]", $goal_add);
		} else {
			$date_comp = "N/A";
			$goal = $goal_add;
			$ans = 0;
		}
	
		$sql = "INSERT INTO ".TABLE_PREFIX."goals VALUES (0, '$ans', '$goal', '$user', '$uid', '$date_add', '$date_comp')";
		$result = $db->query($sql);

		if($goal == "" || $goals == null) {
			echo "Sorry, but please go <a href='{$mybb->settings['bburl']}/goals.php'>back</a> and enter a goal.";
		} else {
			if(!$result) {
				echo "Sorry, but there was an error with adding the goal.<br />";
				mysql_error();
			} else {
				echo "You added the goal: <br />
					<blockquote>Goal: " . $goal . "<br />
								Username: " . $user . "<br />
								Completed: " . $ans . "<br />
								Date Added: " . $date_add . "<br />
								Date Completed: " . $date_comp . "<br />
					</blockquote>
					(A 1 = Completed, a 0 = Not Completed)<br />
					<a href='{$mybb->settings['bburl']}/goals.php'>Add another goal or view the current goals</a>.<br />";
			}
		}
	}
} elseif ($_GET['a'] == 'delete') {
	if($mybb->user['uid'] != 4) {
		echo "You are not allowed to delete any goals.<br />
			<a href='{$mybb->settings['bburl']}/goals.php'>View the current goals</a>.<br />";
	} else {
		$goal = $_POST['goal_delete'];
	
		$sql = "DELETE FROM ".TABLE_PREFIX."goals WHERE goal = '$goal'";
		$result = $db->query($sql);
		
		if($goal == "" || $goals == null) {
			echo "Sorry, but please go <a href='{$mybb->settings['bburl']}/goals.php'>back</a> and enter a goal.";
		} else {
			if(!$result) {
				echo "Sorry, but there was an error with adding the goal.<br />";
				mysql_error();
			} else {
				echo "You Deleted the goal: <br />
					<blockquote>Goal: " . $goal . "<br />
					</blockquote>
					<a href='{$mybb->settings['bburl']}/goals.php'>Delete another goal or view the current goals</a>.<br />";
			}
		}
	}
} elseif ($_GET['a'] == 'update') {
	if($mybb->user['uid'] != 4) {
		echo "You are not allowed to update any goals.<br />
			<a href='{$mybb->settings['bburl']}/goals.php'>View the current goals</a>.<br />";
	} else {
		$goal_update = $_POST['goal_update'];
		$goal = str_replace("[ ]", "[X]", $goal_update);
		$ans = 1;
		$date_comp = date("D, M d-Y h:i:s A");
	
		$sql = "UPDATE ".TABLE_PREFIX."goals SET ans = '$ans', date_comp = '$date_comp', goal = '$goal' WHERE goal = '$goal_update'";
		$result = $db->query($sql);
	
		if($goal == "" || $goals == null) {
			echo "Sorry, but please go <a href='{$mybb->settings['bburl']}/goals.php'>back</a> and enter a goal.";
		} else {
			if(!$result) {
				echo "Sorry, but there was an error with adding the goal.<br />";
				mysql_error();
			} else {
				echo "You updated the goal: <br />
					<blockquote>Goal: " . $goal . "<br />
								Completed: " . $ans . "<br />
								Date Completed: " . $date_comp . "<br />
					</blockquote>
					(A 1 = Completed, a 0 = Not Completed)<br />
					<a href='{$mybb->settings['bburl']}/goals.php'>Update another goal or view the current goals</a>.<br />";
			}
		}
	}
} else {
	echo "	{$usercpnav}<td class='tcat'><span class='smalltext'><strong>Current Goals</strong></span></td>
		</tr>
		<tr>
			<td class='trow1'><span class='smalltext'>";
			if($mybb->user['uid'] == 1) {
				echo "You can use these forms to update the Goals database.<br />
					<fieldset>
						<legend>Add a Goal</legend>
						<form name='goal_add' action='{$mybb->settings['bburl']}/goals.php?a=add' method='post'>
							Goal Name: <input type='text' name='goal_add' /><br />
							Completed:<br />
							<input type='radio' name='ans_add' value='1' /> Yes &nbsp;&nbsp; <input type='radio' name='ans_add' value='0' /> No<br />
							(Must use [ ] at the beginning.)<br />
							(Eg. [ ] 100 Members)<br />
							<input type='submit' value='Submit' onClick='return check_goal_add();' />
						</form>
					</fieldset>
					
					<br />
					
					<fieldset>
						<legend>Delete a Goal</legend>
						<form name='goal_delete' action='{$mybb->settings['bburl']}/goals.php?a=delete' method='post'>
							Goal Name: <input type='text' name='goal_delete' /><br />
							(Must use [ ] at the beginning.)<br />
							(Eg. [ ] 100 Members)<br />
							<input type='submit' value='Submit' onClick='return check_goal_delete();' />
						</form>
					</fieldset>
					
					<br />
					
					<fieldset>
						<legend>Update a Goal</legend>
						<form name='goal_update' action='{$mybb->settings['bburl']}/goals.php?a=update' method='post'>
							Goal Name: <input type='text' name='goal_update' /><br />
							(Must use [ ] at the beginning.)<br />
							(Eg. [ ] 100 Members)<br />
							<input type='submit' value='Submit' onClick='return check_goal_update();' />
						</form>
					</fieldset>";
			}
			
			echo "</span>
				<br />
				<table width='100%'>
					<tr>
						<th>Goal ID</th>
						<th>Goal</th>
						<th>Added By</th>
						<th>Added</th>
						<th>Completed</th>
					</tr>";
					
			$query = $db->simple_select("goals",  "*", "1=1", array("order_by" => 'goalid'));
			while ($result = $db->fetch_array($query)) {
				$goalid = $result['goalid'];
				$goal = $result['goal'];
				$user = $result['user'];
				$uid = $result['uid'];
				$date_add = $result['date_add'];
				$date_comp = $result['date_comp'];
				
			$sql = "SELECT `uid` FROM `".TABLE_PREFIX."users` WHERE `username` = '$user' ";
				$result2 = $db->fetch_array($sql);
				$userid = $result2['uid'];
				
				echo "<tr>	
						<td>$goalid</td>
						<td>$goal</td>
						<td><a href='{$mybb->settings['bburl']}/member.php?action=profile&uid=$uid' target='_blank'>$user</a></td>
						<td>$date_add</td>
						<td>$date_comp</td>
					</tr>";
			}
			
			echo "</table>
				</td>";
}
echo "</tr>
	</table>
	{$footer}
</body>
</html>";
?>



now save and go to your template and add a new page called goals and paste this code there


<html>
<head>
<title>{$mybb->settings['bbname']} - Goals</title>
{$headerinclude}
</head>
<body>
{$header}


now save and go to mysite.com/goals.php


I added so that the page worked, but there is some kind of bug after creating 3 tasks, an error appears MySql yet I do not know what exactly it is, but I think someone can fix it and help us with this.
exactly the MySql error is showing that's why i said it's not working properly.