Advertisement
Guest User

php/smarty

a guest
May 6th, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.21 KB | None | 0 0
  1. //The routing system i made:
  2. //
  3. //using the Smarty templating library to help seperate html from php.
  4. /////////////////////////////////////////////////////////////////////
  5. //Smarty set up.
  6. $smarty = new Smarty;
  7. $smarty->setTemplateDir('classes/Smarty/templates');
  8. $smarty->setCompileDir('classes/Smarty/templates_c');
  9. $smarty->setCacheDir('classes/Smarty/cache');
  10. $smarty->setConfigDir('classes/Smarty/configs');
  11. $smarty->left_delimiter = '!{'; //redefining left delimiter so there isn't confustion with jQuery or any other front end lang.
  12. $smarty->right_delimiter = '}!'; // same as the latter, but the closing delimiter for parsing reasons.
  13.  
  14. //assigning smarty to use for templates
  15.  
  16. $smarty->assign('uid',$s->data["id"]);
  17. $smarty->assign('user',$s->data["username"]);
  18. $smarty->assign('name',$s->data["name"]);
  19. $smarty->assign('picture',$s->data["picture"]);
  20. $smarty->assign('email',$s->data["email"]);
  21. $smarty->assign('perm',$s->data["authlevel"]);
  22.  
  23. //connect to database
  24. $mysql = new Mysql_Conn("****","******","***fullerton.edu","******");
  25. $conn = $mysql->make_conn();
  26. $mysql->sel_db();
  27.  
  28. //routing////////////////////////////////////////////////////////////
  29. switch ($page) {
  30.     case "home" :
  31.    
  32.         //logic for updating informaion
  33.         if($form == "account"){
  34.             switch ($extra[0]){
  35.                 case "general":
  36.                     updateName($_POST['fullname'],$smarty,$s);
  37.                 break;
  38.             }      
  39.         }
  40.        
  41.         $smarty->display('home.tpl');
  42.         break;
  43.     case "message" :
  44.         $smarty->display('message.tpl');
  45.         break;
  46.     case "club" :
  47.         $smarty->display('club.tpl');
  48.         break;
  49.     case "forum" :
  50.         $smarty->display('forum.tpl');
  51.         break;
  52.     case "chat" :
  53.         $smarty->display('chat.tpl');
  54.         break;
  55.     case "logout" :
  56.         $s->expire();
  57.         echo "you have been logged out. <a href=index.php>go home tina</a>";
  58.         break;
  59.     default:
  60.         //echo "404 error";
  61.         break;
  62. }
  63.  
  64. ?>
  65. /////////////////////////////////////////////////////////////////////
  66. //the function:
  67. /////////////////////////////////////////////////////////////////////
  68. <?     
  69. function updateName($newName,$y,$s)
  70. {
  71.    
  72.     if($newName != $s->data['name'])
  73.     {
  74.         $s->data['name'] = $newName; //update session data
  75.         $y->assign('name',$newName);
  76.         $query = "UPDATE user SET fullname='".$newName."' WHERE u_id ='".$s->data['id']."'"; //update database
  77.         if(mysql_query($query))
  78.             $message = "name updated";
  79.  
  80.     }else{
  81.             $message = "name was the same derp face, thus nothing was changed. Thanks for wasting connection resources.";
  82.     }
  83.     //cool, now everything is updated now redirect to portal with successful message   
  84.     header("location:portal.php?page=home&message=".$message);
  85.     //update smarty template var
  86. }
  87. ?>
  88.  
  89.  
  90. /////////////////////////////////////////////////////////////////////
  91. //home.tpl
  92. /////////////////////////////////////////////////////////////////////
  93.  
  94. !{include file="header.tpl" title="theCMS" nocache}!
  95.  
  96. <div id="container">
  97.  
  98. !{if $perm eq 1}!
  99.    access: Super Admin.
  100.    name after update: !{$name nocache}!
  101.    !{include file="home/account.tpl" nocache}!
  102.    !{include file="home/newClub.tpl" nocache}!
  103.    !{include file="home/manageUsers.tpl" nocache}!
  104. !{elseif $perm eq 2}!
  105.    access: Club Admin.
  106.    !{include file="home/account.tpl" nocache}!
  107. !{elseif $perm eq 3}!
  108.    access: Club Member.
  109.    !{include file="home/account.tpl" nocache}!
  110. !{elseif $perm eq 4}!
  111.    access: Newb.
  112.    !{include file="home/account.tpl" nocache}!
  113. !{/if}!
  114.  
  115. </div>
  116.  
  117. !{include file="footer.tpl" nocache}!
  118.  
  119. /////////////////////////////////////////////////////////////////////
  120. //account.tpl
  121. ////////////////////////////////////////////////////////////////////////////
  122. <div id="account">
  123.     <h2>Account Information for : !{$user}!</h2>
  124.     <span class="info">
  125.     <h3>General Info</h3>
  126.     <form action="portal.php?page=home&form=account&extra[]=general&message=Information+Updated" method="POST" name="general" id="general" enctype="multipart/form-data">
  127.         <label for="username">Username: </label><input type="text" value="!{$user}!" name="username" disabled /><br />
  128.         <label for="fullname">Full Name: </label><input type="text" value="!{$name}!" name="fullname"  /><br />
  129.         <label for="email">Email: </label><input type="text" value="!{$email}!" name="email"  /><br />
  130.         <label for="picture">Picture: </label>update?<input name="update" type="checkbox" value="true"><input type="file" value="!{$picture}!" name="picture" /><br />
  131.         <input type="submit" value="update info">
  132.     </form>
  133.     <h3>Change Password !</h3>
  134.     <form action="portal.php?page=home&form=account&extra[]=changepw&message=Password+Changed" method="POST" name="changepw" id="changepw" enctype="multipart/form-data">
  135.         <label for="cpw">Current Password: </label><input type="password" value="" name="cpw"  /><br />
  136.         <label for="npw">New Password: </label><input type="password" value="" name="npw"  /><br />
  137.         <label for="rnpw">Repeat Password: </label><input type="password" value="" name="rnpw" /><br />
  138.         <input type="submit" value="change pw">
  139.     </form>
  140.     </span>
  141.     <span class="pic">
  142.     <img src="prof_pics/!{$picture}!" alt="!{$user}!'s profile picture" width="200" height="200" />
  143.     </span>
  144.     <br style="clear:left;" />
  145. </div>
  146. `
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement