WCDDL V1 (Site Editor MOD)

Status
Not open for further replies.

litewarez

Active Member
1,367
2008
1
0
Heya, i just coded this for some dood as a favour and thought it would be rude not to share so here it is

Just add all this code bofore the ?> at the end of the funcs.php file
PHP:
function admin_edit_sites(){
	global $pg,$limit,$page,$go,$q,$id;
	$mode = $_GET['mode'];
	switch($mode){
		case '':
		default:
			//For Showing all sites
			$query = "SELECT * FROM wcddl_sites LIMIT ".$pg.",".$limit;
			$query = mysql_query($query);
			$fetched = mysql_num_rows($query); // pagination
			$out = '<table width="100%">';
			$out .= "<tr><td>Sitename</td><td>Email</td><td>Rating</td></tr>";
			while($row = mysql_fetch_assoc($query)){
				$out .= "<tr>
					<td>
<a href=\"?go=".$go."&amp;mode=edit&amp;id=".(int)$row['id']."\">".$row['name']."</a></td>
					<td><a href=\"mailto:".$row['email']."\">".$row['email']."</a></td>
					</tr>";
			}
			$out .= "</table>";
			//Just some fast pagination for you :D
			$out .= '<div>';
			if($page > 1){$out .= '<a href="?go='.$go.'&amp;page='.($page-1).'">&laquo; Prev</a> ';}
			$out .= '<strong>('.$page.')</strong>'; // current page
			if($fetched >= $limit){	$out .= '<a href="?go='.$go.'&amp;page='.($page+1).'">Next &raquo;</a> ';}
			$out .= '</div>';
			echo $out;
		break;
		case 'edit':
			//Edit Mode
			if(isset($id)){
				$query = "SELECT * FROM wcddl_sites WHERE id = ".mysql_real_escape_string($id);
				$site_data = mysql_fetch_assoc(mysql_query($query)); // single row
				if($site_data !== false){ // Make sure we have download
					$template = '<table width="100%">';
					$template .= '<form method="post" action="?go='.$go.'&amp;mode=save&amp;id='.$id.'">';
						//Indepth form items
						$template .= '<input type="hidden" name="update" value="true" />';
						$template .= "<tr><td>Site name</td><td><input type=\"text\" name=\"name\" 
						value=\"".$site_data['name']."\" /></td></tr>";
						$template .= "<tr><td>Site url</td><td><input type=\"text\" name=\"url\" 
						value=\"".$site_data['url']."\" /></td></tr>";
						$template .= "<tr><td>Site email</td><td><input type=\"text\" name=\"email\" 
						value=\"".$site_data['email']."\" /></td></tr>";
						$template .= '<tr><td colspan="2"><input type="submit" value="Update" /></td></tr>';
					$template .= "</form>";
					$template .= "</table>";
					echo $template;
				}else{
					echo "Hmmmm, Download (".$id.") does not exists!";
				}
			}else{
				echo "Unable to get id from url!";
			}
		break;
		case 'save':
			if($id > 0 && isset($_POST)){
				$query = "UPDATE wcddl_sites SET name = '%s', url = '%s', email = '%s', WHERE id = %d";
				$query = sprintf($query,mysql_real_escape_string($_POST['name']),mysql_real_escape_string($_POST['url'])
				,mysql_real_escape_string($_POST['email']),(int)$id);
				$check = @mysql_query($query);
				if($check === false){
					echo 'For some reason we was unable to update the database! no changes were made';
				}else{
					echo '('.$_POST["name"].') Updated!, <a href="?go='.$go.'">Go back to editor!</a>';
				}
			}else{
				echo 'There was an error, please make sure you came here for the edit form';
			}
		break;
	}
	echo '<div style="clear:both;font-waight:bold;text-align:center">Site editor by Litewarez</div>';
}

Then open your admin/index.php and find your navigation block and add the link

Code:
<a href="index.php?go=edit_sites">Edit Sites</a> |

Meh.. enjoy
 
22 comments
Dunno, just was the sys he was running, no point in letting it go waste and some people are established with v1 and too much trouble to upgrade!
 
Actually, v1 is basically, for people who even know Lesser Coding.
But v2 is optimized so that it can give good page loads, better performance, etc.
 
There is a lot more mods out there for wcddl v1 over 2 at the moment that is why i had chosen it.

I have done alot of work to optimize the wcddl v1 and a lot more work is to come, so it could easily compare to v2 but with the custom mods :P
 
Either way works, sprintf, intval, strval, floatval, (int), etc.

As long as the code works, it doesn't matter much since its only a small piece of the whole mod.
 
yea im one for not mixing my code with my source but the way the system is bade you have to mix code but i use sprintf so i dont have to put variables within a string etc, i belive that php has to attempt to work out more data this way, where as sprintf im telling php what type of variable its dealing with :D
 
Status
Not open for further replies.
Back
Top