Location: PHPKode > projects > FPCode > fpcode091/fpcode/includes/story_manager.inc.php
<?
//
//	FPCode v0.9, Date 2002-01-11
//
//	Copyright (c) 2002 Wen-Yu Chang and FrostyPlace.com. All rights reserved.
//
//	The contents of this file constitute Original Code as defined in and
//	are subject to the GNU Library General Public License (the
//	"License").  You may not use this file except in compliance with the
//	License.  Please obtain a copy of the License at
//	http://www.gnu.org/licenses/gpl.html and read it before using this file.
//	
//	This Original Code and all software distributed under the License are
//	distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
//	EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
//	INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
//	FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
//	License for the specific language governing rights and limitations
//	under the License.
//
//

	require_once("../includes/config.inc.php");			// Load config params
	require_once("{$fpconfig['root_path']}/includes/dbconnect.inc.php");		//All the db stuff

	function change_state($item_id, $mode){
		
		
		$my_query = "UPDATE stories SET active = $mode WHERE story_id = $item_id";
		
		$result = mysql_query($my_query);	
	}
	
	
	function delete_row($item_id){
		$my_query = "DELETE FROM stories WHERE story_id = $item_id";
		
		$result = mysql_query($my_query);	
	}
	
	function insert_new_row($item_text, $item_url){
	
		if(!get_magic_quotes_gpc()){
			$the_text = addslashes($item_text);
			$the_url = addslashes($item_url);
		} else {
			$the_text = $item_text;
			$the_url = $item_url;
		}
			
		$my_query = "INSERT INTO quickies (q_id, q_title, q_link, post_date, active) " .
					"VALUES( NULL, '$the_text', '$the_url', now(), 1 )";
		
		$result = mysql_query($my_query);

	}


	function print_total_rec(){
		$my_query = "SELECT count(*) as count FROM stories ";
			
		$result = mysql_query($my_query);
		
		$row = mysql_fetch_array($result);
		
		$rec_count = $row['count'];
		
		echo "Á`¸ê®Æµ§¼Æ¡G$rec_count ";
		
		if($result) mysql_free_result($result);
	}

	
	function print_items($start, $len, $sort_by, $item_mode, $doc_type){
		global $PHP_SELF;

		$sel_back = "selected";
		$sel_fore = "";
		$where_str = "";
		
		if($start >= 0 && $len > 0){
			$limit_str = "LIMIT 0, $len";
		} else {
			$limit_str ="LIMIT 0, 30";
			$len = 30;
		}
		
		if($sort_by == "backward"){
			if($start) $where_str = "WHERE story_id >= $start ";
			else  $where_str = "WHERE 1 ";
			$sel_fore = "selected";
			$order_str = "asc";
		} else {
			$sort_by  = "forward";
			if($start) $where_str = "WHERE story_id <= $start ";
			else  $where_str = "WHERE 1 ";
			$sel_back = "selected";
			$order_str = "desc";
		}
		
		switch($item_mode){
		
			case 1:			// Active only
				 $where_str .= " AND active = 1 ";
				 $show_active  = "selected";
			break;
			
			case 2:			// Inactive only
				 $where_str .= " AND active = 0 ";
				 $show_inactive = "selected";		
			break;
			
			case 3:			// New items only
				 $where_str .= " AND active = -1 ";
				 $show_new = "selected";		
			break;
			
			default:		// Show all
				$show_all = "selected";			
		}
		
		
		switch($doc_type){
		
			case 1:			// News only
				 $where_str .= " AND is_report <> 1 ";
				 $show_news  = "selected";
			break;
			
			case 2:			// Reports only
				 $where_str .= " AND is_report = 1 ";
				 $show_report = "selected";		
			break;
			
			default:		// Show all
				$show_all_doc = "selected";			
		}
		

		$my_query = "SELECT story_id, story_title, is_report, active, unix_timestamp(post_time) as post_time ".
					"FROM stories $where_str ".
					"ORDER BY story_id $order_str $limit_str";
		
		$result = mysql_query($my_query);
		
		if (mysql_num_rows($result) > 0){
			$the_first_row = true;
			$cnt = 0;
			
			while ($row = mysql_fetch_array($result)){
				$r_id = $row['story_id'];
				$r_title = $row['story_title'];
				($row['is_report'] > 0) ? $r_report = "³ø¾É" : $r_report = "·s»D";				

				if($row['active'] > 0){
					$r_active = "<font color=\"red\">¤W½u</font>";
					$r_state_btn = "Â÷½u";
					$r_state_mode = "item_off";
				} else {
					if($row['active'] == 0) $r_active = "<font color=\"green\">Â÷½u</font>";
					else $r_active = "<font color=\"blue\">·s¼W</font>";
					$r_state_btn = "¤W½u";
					$r_state_mode = "item_on";
				}
				
				if($cnt == 0) $bg_color="#eaeaea";
				else  $bg_color="#ffffff";
				
				if($the_first_row){
?>				
				<table width="100%" border="0" cellpadding="2" cellspacing="0" >
				<tr><td align="center" bgcolor="#eeeeee" colspan="5"><form action="<? echo $PHP_SELF; ?>" method="post">
				<input type="hidden" name="mode" value="update_view">
				±q <input type="text" name="first_row" value="<? echo $r_id; ?>" size="4" maxlength="3"> ¸¹¬ö¿ý¶}©l 
				<select name="direction" class="form_elements">
				<option value="forward" <? echo $sel_back; ?>>¦V«e</option>
				<option value="backward" <? echo $sel_fore; ?>>¦V«á</option>
				</select> Åã¥Ü¡A¨C¦¸Åã¥Ü <input type="text" name="row_num" value="<? echo $len; ?>" size="4" maxlength="3"> µ§
				<select name="show_active" class="form_elements">
				<option value="0" <? echo $show_all; ?>> -- </option>
				<option value="1" <? echo $show_active; ?>>¤W½u</option>
				<option value="2" <? echo $show_inactive; ?>>Â÷½u</option>
				<option value="3" <? echo $show_new; ?>>·s¼W</option>
				</select> ªº
				<select name="show_type" class="form_elements">
				<option value="0" <? echo $show_all_doc; ?>>©Ò¦³¤å¥ó</option>
				<option value="1" <? echo $show_news; ?>>·s»D</option>
				<option value="2" <? echo $show_report; ?>>³ø¾É</option>
				</select>
				<input type="submit" name="update_list" value="§ó·s" class="form_elements">
				</form><hr></td></tr>
<?
					$the_first_row = false;
				
				}
				
				$post_date = date ("Y/m/d", $row['post_time']) . "<br>" . date ("g:i a", $row['post_time']);	

?>
				<tr bgcolor="<? echo $bg_color; ?>">
				<td colspan="5"><form action="<? echo $PHP_SELF; ?>" method="post" onSubmit="return check_form()">
				<input type="hidden" name="mode" value="update_row">
				<input type="hidden" name="item_id" value="<? echo $r_id; ?>">
				<input type="hidden" name="first_row" value="<? if($start) echo $start; else echo ""; ?>">
				<input type="hidden" name="row_num" value="<? echo $len; ?>">
				<input type="hidden" name="direction" value="<? echo $sort_by; ?>">
				<table width="100%" border="0" cellpadding="2" cellspacing="2">
				<th class="table_hdr" width="40" nowraps>½s¸¹</th>
				<th class="table_hdr" width="120" nowraps>­×§ï¤é´Á</th>
				<th class="table_hdr" nowraps>¼Ð ¡@ ÃD</th>
				<th class="table_hdr" width="60" nowrap>Ãþ¡@ §O</th>
				<th class="table_hdr" width="60" nowrap>ª¬¡@ ºA</th>
				<th class="table_hdr" width="180">«ü¡@ ¥O</th>
				<tr>
				<td class="form_elements" align="center" width="40" nowraps><? echo $r_id; ?></td>
				<td class="form_elements" align="center" width="120" nowrap><? echo $post_date; ?></td>
				<td class="form_elements" align="left" nowrap><? echo htmlspecialchars($r_title); ?></td>
				<td class="form_elements" align="center" width="60" nowrap><? echo $r_report; ?></td>
				<td class="form_elements" align="center" width="60" nowrap><? echo $r_active; ?></td>
				<td class="form_elements" align="center" width="180" nowrap>
				<button type="button" name="previw" onClick="open_preview_window(<? echo $r_id; ?>);">¹wÄý</button>
				<input type="submit" name="<? echo $r_state_mode; ?>" value="<? echo $r_state_btn; ?>" class="form_elements"> 
				<input type="submit" name="update_item" value="½s¿è" class="form_elements"> 
				<input type="submit" name="delete_item" value="§R°£" class="form_elements" onClick="set_delete=true;"></td>
				</tr></table></form>
				</td></tr>
				
<?			
				$cnt = ($cnt+1) % 2;
				
				}

			echo "</table>\n";
		} else {
?>
				<tr><td align="center" bgcolor="#eeeeee" colspan="5"><form action="<? echo $PHP_SELF; ?>" method="post">
				<input type="hidden" name="mode" value="update_view">
				±q <input type="text" name="first_row" value="<? echo $r_id; ?>" size="4" maxlength="3"> ¸¹¬ö¿ý¶}©l 
				<select name="direction" class="form_elements">
				<option value="forward" <? echo $sel_back; ?>>¦V«e</option>
				<option value="backward" <? echo $sel_fore; ?>>¦V«á</option>
				</select> Åã¥Ü¡A¨C¦¸Åã¥Ü <input type="text" name="row_num" value="<? echo $len; ?>" size="4" maxlength="3"> µ§
				<select name="show_active" class="form_elements">
				<option value="0" <? echo $show_all; ?>> -- </option>
				<option value="1" <? echo $show_active; ?>>¤W½u</option>
				<option value="2" <? echo $show_inactive; ?>>Â÷½u</option>
				<option value="3" <? echo $show_new; ?>>·s¼W</option>
				</select> ªº
				<select name="show_type" class="form_elements">
				<option value="0" <? echo $show_all_doc; ?>>©Ò¦³¤å¥ó</option>
				<option value="1" <? echo $show_news; ?>>·s»D</option>
				<option value="2" <? echo $show_report; ?>>³ø¾É</option>
				</select>
				<input type="submit" name="update_list" value="§ó·s" class="form_elements">
				</form><hr></td></tr>
			<tr><td align="center" bgcolor="#eeeeee"><br><b>¸ê®ÆÄ椺®e¬°ªÅ¥Õ¡C</b><br><br></td></tr>	
		
<?		}
	
		if($result) mysql_free_result($result);

	}
	
	
	function print_footer(){
?>	
	<div class="footer_txt">Copyright &#169; 1996 - 2002 FrostyPlace.com</div>
<?
	}	
?>
Return current item: FPCode