Godkid Posted February 23, 2004 Posted February 23, 2004 Hey guys I wanted to be able to close and open my store directly from admin and be able to literally turn off the store so that even external links would lead to a "closed sign" Well I set to doing it and decided I'd try to detail the process here just incase someone else wanted to do this..or someone culd do it cleaner... (matter of fact I don't even know if there's a contrib of this sort already).. anywho NOTICE: I am still a script kiddie and rely on Dreamweaver for the appropriate code. If there's anyone that can clean this up, please go ahead. Step 1: I firstly created a table in the database and added 3 fields - 1 to use as the row selection field, 1 to keep the store status (open/closed) and the final one to keep the date of the change so I could track how long the store was closed etc. Step 2: I edited the admin index.php file to include a box that would tell me current store state, and ask me if I wanted to change the state: // my edit to control store status $store_state_query = tep_db_query("select * from " . TABLE_STORE_STATE); $store_status = tep_db_fetch_array($store_state_query); $change_state_list = array('<a href="java script:;" onClick="MM_openBrWindow(\'yayaya.php?newstate=open&action=none\',\'statechange\',\'width=200,height=75\')">open</a>', '<a href="java script:;" onClick="MM_openBrWindow(\'yayaya.php?newstate=closed&action=none\',\'statechange\',\'width=200,height=75\')">close</a>'); if ($store_status[store_state] == open) { $change_state = $change_state_list[1]; } if ($store_status[store_state] == closed) { $change_state = $change_state_list[0]; } $heading = array(); $contents = array(); $heading[] = array('params' => 'class="menuBoxHeading"', 'text' => 'Store Status'); $contents[] = array('params' => 'class="infoBox"', 'text' => BOX_STORE_STATE . ' ' . '<b><font color="#FF0000">' . $store_status[store_state] . '</font></b>. Would you like to <b>' . $change_state . '</b> it now? <br><br>'. 'Changed: ' . $store_status[store_state_date]); $box = new box; echo $box->menuBox($heading, $contents); echo '<br>'; // end my edit to control store status I use decided to use a popup window to display a confirmation page and passed the variables and values to be used in the hidden form by appending them to the url. << remember I use Dreamweaver so that why there's that "branded" type popup function >> Step 3: I created the confirmation page (of course) which simply takes the variables passed and updates the database. After updating it gives you a little blurb telling you what the status of the store was changed to and the date. It also has a close and refresh script so that when the window closes it refreshes the admin index.php page to show you the surrent store state. << remember I use Dreamweaver and didn't to use the TEP/OSC codings >> <?phpfunction GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } $editFormAction = $HTTP_SERVER_VARS['PHP_SELF']; if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) { $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING']; } if ((isset($HTTP_POST_VARS["MM_update"])) && ($HTTP_POST_VARS["MM_update"] == "state")) { $updateSQL = sprintf("UPDATE store_status SET store_state=%s, store_state_date=%s WHERE `primary`=%s", GetSQLValueString($HTTP_POST_VARS['store_state'], "text"), GetSQLValueString($HTTP_POST_VARS['store_state_date'], "date"), GetSQLValueString($HTTP_POST_VARS['primary'], "text")); mysql_select_db($database, $xaxaxa); $Result1 = mysql_query($updateSQL, $xaxaxa) or die(mysql_error()); $updateGoTo = "yayaya.php?action=ending"; header(sprintf("Location: %s", $updateGoTo)); } mysql_select_db($database, $xaxaxa); $query_store_states = "SELECT * FROM store_status"; $store_states = mysql_query($query_store_states, $xaxaxa) or die(mysql_error()); $row_store_states = mysql_fetch_assoc($store_states); $totalRows_store_states = mysql_num_rows($store_states); $date_now = date("Y d j"); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>store state change</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script> function closeRefresh() { opener.location.reload(); self.close(); } </script> </head> <body> <?php if ($action == "ending") { echo 'Store status changed to <b>' . $row_store_states['store_state'] . '</b> on ' . $row_store_states['store_state_date'] . '</br></br>'; echo '<center><font color="#999999" size="1" face="Verdana, Arial, Helvetica, sans-serif"><strong><a href="java script:closeRefresh();">close this window</a></strong></font></center>'; } else{ ?> <form name="state" method="POST" action="<?php echo $editFormAction; ?>"> <p> <input name="store_state" type="hidden" id="store_state" value="<?php echo $newstate; ?>"> <input name="primary" type="hidden" id="primary" value="store"> <input name="store_state_date" type="hidden" id="store_state_date" value="<?php echo $date_now; ?>"> <input type="hidden" name="MM_update" value="state"> </p> <p align="center"><strong>Confirm status change:</strong></p> <p align="center"><strong> <input type="image" src="images/confirm.gif" alt="confirm" value="Submit" width="64" height="18" border="0"> <a href="java script:close();"><img src="images/cancel.gif" alt="cancel" width="64" height="18" border="0"></a> </strong></p> </form> <?php } mysql_free_result($store_states); ?> Ok... now that I'd successfully created the admin side Step 4: I then designed a "Store Closed" page, in normal HTML and then edited the catalog index.php page to look like this: <?php/* $Id: index.php,v 1.1 2003/06/11 17:37:59 hpdl Exp $ osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright © 2003 osCommerce Released under the GNU General Public License */ require('includes/application_top.php'); // my edit for store status $store_state_query = tep_db_query("select * from " . TABLE_STORE_STATE); $store_status = tep_db_fetch_array($store_state_query); if ($store_status[store_state] == closed) { ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="description" content=" "> </head> <body> page code here </body> </html> <?php } else { // the following cPath references come from application_top.php $category_depth = 'top'; <?php } else { // the following cPath references come from application_top.php $category_depth = 'top'; etc etc and that's it! You can see the code in action at http://shop.digisolvit.com
paulm2003 Posted February 23, 2004 Posted February 23, 2004 [off topic]Don't know if you are still working on it, but your pages only look good (very good indeed!) in IE. But Mozilla and Opera there are some errors[/off topic] If you happen to use the BTSv1.2 you can simply create a closed template and set it in admin as default (and set to disallow url template switching in admin). Not sure if it works better or worse than your solution but it is very easy to implement.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.