Jump to content
xisto Community
XIII

How To Create A Control Panel?

Recommended Posts

I'm now coding a site that i need adminstrators and moderators to have access to a control page for the contents of some pages.

i have already coded a control page that makes adminstrators able to do the following:

 

1- add, ban or suspend members.

2- modify members groups and assign groups to members.

3- viewing the login logs, users details and edit these details.

 

i finished this page and it's already working so good.

the second control panel i want to code is supposed to give the adminstrators and moderators the abillity to do the following functions:

 

a- for adminstrators :

 

1- add/update values in a mysql database's table column which will be a quantity of object (x).

2- upload photos to a main folder called "signals" and this images to be added in a web page under name "y.jpg" and to replace an older image with the same name <<----- is it possible??

3- add news to a database table called news which contains 2 fields, id "auto-insertment field" and another field called news and need it to update the page which will display this news called news.php which will always contain last 20 news pieces.

4- view/edit users accounts which will be saved as a table per user in the another database called users.

 

b- for moderators:

 

just functions no. 2 and 3 which are:-

 

1- upload photos to a main folder called "signals" and this images to be added in a web page under name "y.jpg" and to replace an older image with the same name <<----- is it possible??

2- add news to a database table called news which contains 2 fields, id "auto-insertment field" and another field called news and need it to update the page which will display this news called news.php which will always contain last 20 news pieces.

 

i'm still working on it but really it kills me thinking, specially that part for uploading a photo to a main folder, seems like so hard to me to do it, i hope anyone can help.

 

P.S: i use PHP/MySQL for all these stuffs.

Share this post


Link to post
Share on other sites

2- upload photos to a main folder called "signals" and this images to be added in a web page under name "y.jpg" and to replace an older image with the same name <<----- is it possible??

Yes, it is possible to do, the only thing to care about is that you must set write priviligies to this folder with CHMOD 777.

3- add news to a database table called news which contains 2 fields, id "auto-insertment field" and another field called news and need it to update the page which will display this news called news.php which will always contain last 20 news pieces.

To add new news to your table you only need a page with a FORM with a TEXTAREA field for the news and other page to process the submited data.

 

FormNews.htm:Page with the form, i only put the form elements :unsure:

<form action="addnews.php" method="post">News: <textarea rows="3" name="news" cols="100"></textarea><br /><br /><input name="cmdAdd" type="submit" value="Add News" /></form>
addnews.php:Page that process the submited data to insert into the database.
<?phpfunction safeEscapeString($string){	if (get_magic_quotes_gpc()) {		return $string;	}	else {		return mysql_real_escape_string($string);		// return mysqli_real_escape_string($string);	}}include ("connectdb.php"); // connect and select your database$news=safeEscapeString($_POST["news"]);mysql_query("insert into news(news) values ('$news')")	or die (mysql_errno(). ": " . mysql_error() );mysql_close();Header("Location: FormNews.htm");exit();?>
In your news.php your select statement include the LIMIT clause like this:
<?phpinclude ("connectdb.php"); // connect and select your database$query_rsNews = "SELECT * FROM news ORDER BY id DESC LIMIT 20";$rsNews = mysql_query($query_rsNews) or die(mysql_error());while($row_rsNews = mysql_fetch_array($rsNews)) {  echo $row_rsNews["id"] . $row_rsNews["news"];}?>
For moderators will be the same thing.

 

Best regards,

Share this post


Link to post
Share on other sites

I think I can lead you in the right direction. I won't write any code for you since I think you'll learn more quickly if I just give you some sample code to work with.

It is kind of off the beaten path but there is an example of how to upload files like images to the server at the PHP.net website.
http://us3.php.net/manual/en/features.file-upload.php

Here is the form used to upload files:

<!-- The data encoding type, enctype, MUST be specified as below --><form enctype="multipart/form-data" action="__URL__" method="POST">	<!-- MAX_FILE_SIZE must precede the file input field -->	<input type="hidden" name="MAX_FILE_SIZE" value="30000" />	<!-- Name of input element determines name in $_FILES array -->	Send this file: <input name="userfile" type="file" />	<input type="submit" value="Send File" /></form>
Here is the script that handles that form and uploads the file and moves it to the right directory:

<?php// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead// of $_FILES.$uploaddir = '/var/www/uploads/';$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);echo '<pre>';if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {   echo "File is valid, and was successfully uploaded.\n";} else {   echo "Possible file upload attack!\n";}echo 'Here is some more debugging info:';print_r($_FILES);print "</pre>";?>
I think you should carefully read the entire File-Upload page at PHP.net.

$uploadfile is the name and location that the file will be saved as. If you don't want it to be named the same as the user's name but instead want to have the server name it instead like image001.jpg, then replace that line.

Once uploaded, you can have the file moved or copied with the PHP File System Functions.

For the Moderator / Admin options, since everyone uses the file upload and news options, then we can code that pretty easily. For the Admin only options, we'll need to chack for the user type.

Basically, only show the Admin only options if the user is an Admin:
if($usertype == 'Admin') {	echo "Admin Only Options";}

As for the actual form, the MySQL interface is rather simple. When you load the page, be sure to insert the database values into the form fields. Once the user has made the changes and submits, then the form fields will be inserted into the database using the MySQL UPDATE command. This is done the same as any MySQL querry in PHP. You'll need to review the usage at the MySQL website.
$sql = mysql_query("UPDATE tablename SET fieldname = 'fieldvalue' WHERE fieldname = 'condition'");

You only need to update the fields that change.

I'm not sure how much information about this you'll need so I'll stop for now.

Hope This Helps. :unsure:

vujsa

Share this post


Link to post
Share on other sites

Yes, it is possible to do, the only thing to care about is that you must set write priviligies to this folder with CHMOD 777.

 

For moderators will be the same thing.

 

Best regards,

 


Thank you for your interest in helping me, i will try the news section and i'll post here if it works for me and any update for any error or so on

i need help in uploading section for the code itself, never know what is the function for uploadin to the server, i can modify folder priviligies, this isn't a problem

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.