Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //The routing system i made:
- //
- //using the Smarty templating library to help seperate html from php.
- /////////////////////////////////////////////////////////////////////
- //Smarty set up.
- $smarty = new Smarty;
- $smarty->setTemplateDir('classes/Smarty/templates');
- $smarty->setCompileDir('classes/Smarty/templates_c');
- $smarty->setCacheDir('classes/Smarty/cache');
- $smarty->setConfigDir('classes/Smarty/configs');
- $smarty->left_delimiter = '!{'; //redefining left delimiter so there isn't confustion with jQuery or any other front end lang.
- $smarty->right_delimiter = '}!'; // same as the latter, but the closing delimiter for parsing reasons.
- //assigning smarty to use for templates
- $smarty->assign('uid',$s->data["id"]);
- $smarty->assign('user',$s->data["username"]);
- $smarty->assign('name',$s->data["name"]);
- $smarty->assign('picture',$s->data["picture"]);
- $smarty->assign('email',$s->data["email"]);
- $smarty->assign('perm',$s->data["authlevel"]);
- //connect to database
- $mysql = new Mysql_Conn("****","******","***fullerton.edu","******");
- $conn = $mysql->make_conn();
- $mysql->sel_db();
- //routing////////////////////////////////////////////////////////////
- switch ($page) {
- case "home" :
- //logic for updating informaion
- if($form == "account"){
- switch ($extra[0]){
- case "general":
- updateName($_POST['fullname'],$smarty,$s);
- break;
- }
- }
- $smarty->display('home.tpl');
- break;
- case "message" :
- $smarty->display('message.tpl');
- break;
- case "club" :
- $smarty->display('club.tpl');
- break;
- case "forum" :
- $smarty->display('forum.tpl');
- break;
- case "chat" :
- $smarty->display('chat.tpl');
- break;
- case "logout" :
- $s->expire();
- echo "you have been logged out. <a href=index.php>go home tina</a>";
- break;
- default:
- //echo "404 error";
- break;
- }
- ?>
- /////////////////////////////////////////////////////////////////////
- //the function:
- /////////////////////////////////////////////////////////////////////
- <?
- function updateName($newName,$y,$s)
- {
- if($newName != $s->data['name'])
- {
- $s->data['name'] = $newName; //update session data
- $y->assign('name',$newName);
- $query = "UPDATE user SET fullname='".$newName."' WHERE u_id ='".$s->data['id']."'"; //update database
- if(mysql_query($query))
- $message = "name updated";
- }else{
- $message = "name was the same derp face, thus nothing was changed. Thanks for wasting connection resources.";
- }
- //cool, now everything is updated now redirect to portal with successful message
- header("location:portal.php?page=home&message=".$message);
- //update smarty template var
- }
- ?>
- /////////////////////////////////////////////////////////////////////
- //home.tpl
- /////////////////////////////////////////////////////////////////////
- !{include file="header.tpl" title="theCMS" nocache}!
- <div id="container">
- !{if $perm eq 1}!
- access: Super Admin.
- name after update: !{$name nocache}!
- !{include file="home/account.tpl" nocache}!
- !{include file="home/newClub.tpl" nocache}!
- !{include file="home/manageUsers.tpl" nocache}!
- !{elseif $perm eq 2}!
- access: Club Admin.
- !{include file="home/account.tpl" nocache}!
- !{elseif $perm eq 3}!
- access: Club Member.
- !{include file="home/account.tpl" nocache}!
- !{elseif $perm eq 4}!
- access: Newb.
- !{include file="home/account.tpl" nocache}!
- !{/if}!
- </div>
- !{include file="footer.tpl" nocache}!
- /////////////////////////////////////////////////////////////////////
- //account.tpl
- ////////////////////////////////////////////////////////////////////////////
- <div id="account">
- <h2>Account Information for : !{$user}!</h2>
- <span class="info">
- <h3>General Info</h3>
- <form action="portal.php?page=home&form=account&extra[]=general&message=Information+Updated" method="POST" name="general" id="general" enctype="multipart/form-data">
- <label for="username">Username: </label><input type="text" value="!{$user}!" name="username" disabled /><br />
- <label for="fullname">Full Name: </label><input type="text" value="!{$name}!" name="fullname" /><br />
- <label for="email">Email: </label><input type="text" value="!{$email}!" name="email" /><br />
- <label for="picture">Picture: </label>update?<input name="update" type="checkbox" value="true"><input type="file" value="!{$picture}!" name="picture" /><br />
- <input type="submit" value="update info">
- </form>
- <h3>Change Password !</h3>
- <form action="portal.php?page=home&form=account&extra[]=changepw&message=Password+Changed" method="POST" name="changepw" id="changepw" enctype="multipart/form-data">
- <label for="cpw">Current Password: </label><input type="password" value="" name="cpw" /><br />
- <label for="npw">New Password: </label><input type="password" value="" name="npw" /><br />
- <label for="rnpw">Repeat Password: </label><input type="password" value="" name="rnpw" /><br />
- <input type="submit" value="change pw">
- </form>
- </span>
- <span class="pic">
- <img src="prof_pics/!{$picture}!" alt="!{$user}!'s profile picture" width="200" height="200" />
- </span>
- <br style="clear:left;" />
- </div>
- `
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement