Jump to content

New here looks like an awesome site! Can someone help me with this?


Recommended Posts

I run a classifieds site and im trying to change how the user chooses a category to post a new classified ad in.  Right now its a HUGE drop down list which is annoying for the user to scroll through the huge list.  So i want to make a page with all the categories listed with a check box next to each category.  I know the html part of that but the php is something i dont know anything about.  Thanks!

 

So here goes this is the code from the template for the drop down box:

 

<form action="item.php" name="add_ad" method="post">
<select name="catid" onchange="checkSelectedOption(this.value, document.add_ad,'{$smarty.const.LA_ONLY_STAR}');">
<option value='-1'>{$smarty.const.CHOOSE_CAT}</option>
{$option_list}
</select><--Click the arrow and highlight the category you want your ad placed in and click it.
</form>

----------------------------------------------------------------------------------------------

 

This is the whole item.php code

 

<?
session_start();   
include_once("admin/inc.php");
$pagename = $sitename . " - " . LA_ADD_AD;

$lErrorPay=0;
$lPayCredits=0;
$lPayBold=0;
$lPayWYSIWYG=0;
$lPayPremium=0;
$lIsSpecial=0;
$lIsPremium=0;

if ($set_wysiwyg_editor)
$html_editor=1;

if (!$admin_area)
include_once("header_inc.php");

$tplItem=new TplLoad;

if (!$admin_area)
{
check_valid_user("");
include_once("member_header.php");	
}	
$ad_id=getParam("ad_id","");
$catid=getParam("ad_cat_id","");

$tplItem->assign("phpself",$_SERVER['PHP_SELF']);
$tplItem->assign("set_expire_days_option",$set_expire_days_option);
$tplItem->assign("url", "http://$url");
$tplItem->assign("html_editor", "$html_editor");
$tplItem->assign("set_video_upload", "$set_video_upload");
$tplItem->assign("set_doc_upload", "$set_doc_upload");

if ($admin_area)
$tplItem->assign("url_to_upload", "http://$url/admin/item_upload.php");
else 
$tplItem->assign("url_to_upload", "http://$url/upload_file.php");

if ($admin_area)
$tplItem->assign("url_to_upload_video", "http://$url/admin/item_upload_video.php");
else 
$tplItem->assign("url_to_upload_video", "http://$url/upload_video.php");

if ($admin_area)
$tplItem->assign("url_to_upload_doc", "http://$url/admin/item_upload_other.php");
else 
$tplItem->assign("url_to_upload_doc", "http://$url/upload_other.php");


$lCatCost="";

if ($ad_id)
{
$result = q ("select * from $ads_tbl where ad_id = $ad_id");
$row = mysql_fetch_array($result);
$ad_owner = $row["ad_owner"];
$lCatId = $row["ad_cat_id"];

if ($ad_owner <> $_SESSION["valid_user"] AND !$admin_area)
	criticalError(LA_ERROR,LA_MUSTBEOWNER);	
}
$lCat=getParam("catid",$row["ad_cat_id"]);

if ($lCat)
{

$sql_top = "select cat_name,cat_fatherid,cat_cost ";
if (!empty($_SESSION["la"]) && $set_multilang_cat)
{
	$sql_top .= ",lang_" . $_SESSION["la"];
}
$sql_top.= " from $cat_tbl where cat_id = $lCat AND cat_allow_ads = 'on'";
$result_1 = q ($sql_top);
$row_1 = mysql_fetch_array($result_1);
$catname = $row_1["cat_name"];
$lCatFatherID  = $row_1["cat_fatherid"];
$lCatCost = $row_1["cat_cost"];



}

if ($set_expire_days_option_list && $set_expire_days_option==1)
{
$lExpireListArray=split(",","$set_expire_days_option_list");
foreach ($lExpireListArray as $option)
{
	$lExpireList.="<option value='$option'";
	if ($option==getParam("expire_days",""))
		$lExpireList.=" selected";
	$lExpireList.=">$option " . DAYS . "</option>";
}
	$tplItem->assign("expire_list",$lExpireList);		
}

if (!empty($_SESSION["la"]) && $set_multilang_cat)
{
$lang_catname = "lang_" . $_SESSION["la"];
if (!empty($row_1["$lang_catname"]))
{
	$catname = $row_1["$lang_catname"];
}
}

$tplItem->assign("update_rq",getParam("update_rq",""));
$tplItem->assign("submit",getParam("submit",""));
$tplItem->assign("catname",$catname);
$tplItem->assign("show_form",1);

$lCurrentUser=$_SESSION["valid_user"];
if ($admin_area)
$lCurrentUser=$row["ad_owner"];

$lCurrentUser=(integer) $lCurrentUser;


if ($set_payments AND getParam("update_rq","")=="" && !$admin_area)
{


if (!getExpireStatus($lCurrentUser))
{

	$sql="select pay_credits,pay_bold,pay_premium from $usr_tbl where user_id=$lCurrentUser";
	$res_user=q($sql);
	$row_user=mysql_fetch_array($res_user);
	$lPayCredits=$row_user["pay_credits"];
	$lPayBold=$row_user["pay_bold"];
	$lPayPremium=$row_user["pay_premium"];

	if (!$lCatCost)
		$lCatCost=0;

	$tplItem->assign("set_payments",1);		
	$tplItem->assign("pay_free_credits",$lPayCredits);	
	$tplItem->assign("pay_catcost",$lCatCost);	
	$tplItem->assign("pay_premium",$lPayPremium);	



	if ($lPayCredits<$lCatCost)
	{
		$tplItem->assign("pay_out_of_credits",1);	
		$tplItem->assign("show_form",0);	
		$lErrorPay=1;
	}

}

}

if (getParam("submit","")=="")
{
$lTitle=$row["ad_title"];
$lDescr=$row["ad_description"];
$lUserID=$_SESSION["valid_user"];

}
else 
{
$lTitle=getParam("ad_title","");
$lDescr=getParam("ad_description","");
$lUserID=$_SESSION["valid_user"];
}
$lUserID=(integer) $lUserID;
$tplItem->assign("admin_area",$admin_area);
$tplItem->assign("ad_title",stripcslashes($lTitle));
$tplItem->assign("ad_description",stripcslashes($lDescr));
$tplItem->assign("catid",$lCat);
$tplItem->assign("ad_cat_id",$lCat);
$tplItem->assign("ad_id",getParam("ad_id",$ad_id));

// Find Extra fields in ad table and get values from not empty rows
$i=0;
$data="";
$result_1 = q ("select cat_tpl from $cat_tbl where cat_id = $lCat");
$row_cat = mysql_fetch_array($result_1);
$cat_tpl = $row_cat["cat_tpl"];

$lExtraFieldArray=getMandatoryValues("$cat_tpl",1);
if (is_array($lExtraFieldArray))
{
foreach ($lExtraFieldArray as $item)
{
	$value="e_" . $item["q_field"];
	$lArray[$i]["id"]=$i;	
	$lArray[$i]["field"]=$value;	
	$lStr=getParam($value,"");
	$lValueStr="";	

	if ($lStr)
	{
		if (is_array($lStr))
		{
			foreach ($lStr as $lItem)
				$lValueStr.="$lItem,";

			$lValueStr=substr($lValueStr,0,-1);
		}
		else 
			$lValueStr=$lStr;
	}
	elseif (getParam("submit","")=="")
	{
		$lValueStr=$row[$value];
	}

	if (getParam("submit","") !="")
	{

		if ($item["q_mand"] && empty($lValueStr))
			$errorMsg.= "<li>".LA_YOU_MUST ." <b>" . $item["q_question"] . "</b></li>";
		else if (!empty($item["q_reg_exp"]))
		{
			if (preg_match($item["q_reg_exp"],$lValueStr))	
				$errorMsg.="<li>".$item["q_reg_exp_errormsg"] ." <b>".$item["q_question"]."</b></li>";

		}	
	}


	//$lValueStr=eregi_replace('\\\"',"&quote;",$lValueStr);
	//$lValueStr=eregi_replace("\\\'","&quote;",$lValueStr);

	$lValueStr=stripcslashes($lValueStr);
	$lValueStr=htmlspecialchars($lValueStr,ENT_QUOTES);
	$lArray[$i]["value"]=$lValueStr;
	$lValueStr=addslashes($lValueStr);
	//echo "$lValueStr<br>";
	$data.="$value='$lValueStr',";	
	$i++;
}

$lExtraArray=getExtraAdvValue("$cat_tpl",1,$lArray);
$tplItem->assign("extra_fields_array",$lExtraArray);
}


if (getParam("submit",""))
{	
// Simple Error Checking Start	
if (!$lTitle)
	$errorMsg.="<li>".LA_YOU_MUST ." <b>" . TITLE . "</b></li>";

if (!$lDescr)
	$errorMsg.="<li>".LA_YOU_MUST ." <b>".DESCRIPTION."</b></li>";

if (!$lCat)
	$errorMsg.="<li>".LA_YOU_MUST ." <b>".LA_CAT."</b></li>";

 // Check for banned words. If a banned word appear, raise warning
 $bad_words_list = split(",", $set_bad_words);
 foreach($bad_words_list as $bad) 
 {
 	if ($bad)
 	{
 		$result1 = eregi($bad,$lTitle);
 		$result2 = eregi($bad,$lDescr);
 	}

 	if (!empty($result1) OR !empty($result2))
		$errorMsg.="<li>".LA_BAD_WORDS ." <b>$bad</b><br />";

 }	
// Simple Error Checking Completed
$tplItem->assign("errorMsg", $errorMsg);

if ($errorMsg)
	$tplItem->assign("show_form",1);
	else
{
	$tplItem->assign("submit_ok",1);
	$tplItem->assign("show_form",0);

	if (getParam("ad_id",""))
	{
		## Modified Ad ##
		updateAd($ad_id,$lCurrentUser,$lTitle,$lDescr,$lCat,"","","",$data,$set_inform_admin_update);
	}
	else
    	{
    		## New Ad ##
    		// If credit option and the user is not admin, reduce number of credits by one
    		$lIsSpecial=0;
    		
    		if ($set_payments)
    		{
    			if (!getExpireStatus($lCurrentUser))
    			{
				$sql="update $usr_tbl set pay_credits = pay_credits - $lCatCost where pay_credits>0";
				$sql.=" AND user_id = ".$_SESSION["valid_user"]."";		
				$res_pay=q($sql);
    			}
			$sql="update $usr_tbl set pay_bold = pay_bold - 1 where pay_bold>0 ";
			$sql.=" AND user_id = ".$_SESSION["valid_user"]."";		
			$res_pay=q($sql);

			if ($lPayBold>0)
				$lIsSpecial=1;

			$sql="update $usr_tbl set pay_premium = pay_premium - 1 where pay_premium>0";
			$sql.=" AND user_id = ".$_SESSION["valid_user"]."";		
			$res_pay=q($sql);

			if ($lPayPremium>0)
				$lIsPremium=1;
			else 
				$lIsPremium=0;

    		}
		// Check if the ad has already been posted (exaxtly same ad and user will raise warning)
		$result = q("select ad_id from $ads_tbl where ad_title = '$lTitle' AND ad_owner=$lUserID");
		$num_already_posted = mysql_num_rows($result);

		if ($num_already_posted>0)
		{
			echo "<p><b>" . formatString(LA_POSTED_BEFORE,array(getParam("ad_title",""))) . "</b></p>";
			include_once("member_footer.php");
			include_once("footer_inc.php"); 
			exit;
		}			
		if ($set_expire_days_option==2 AND $set_delete_after_x_days)
			$lNumberOfDays=$set_delete_after_x_days;
		elseif ($set_expire_days_option==1 AND getParam("expire_days",""))
			$lNumberOfDays=(getParam("expire_days",1));

		$ad_id=createAd($lUserID,$lTitle,$lDescr,$lCat,$lNumberOfDays,$lIsSpecial,$lIsPremium,$data,$set_inform_admin_insert);

		if ($ad_id>0)
		{
			$tplItem->assign("submit_ok",$ad_id);
			$tplItem->assign("await_validation",$validation);
			notifyMembersNewAd($lCat,$catname,$ad_id,$lTitle,strip_tags($lDescr),$url);	  
		}					

	} // End of insert/update
	$tplItem->assign("picture_upload_enable", $set_image_upload);
  		$tplItem->assign("ad_id", $ad_id);
  		
} // End IF NOT ERRORMSG Submit

// End of submit information
}


$cat_list="";
if ($admin_area)
$cat_list=getCategoriesDD($lCatId,1);
else if ($ad_id && isset($lCatFatherID))
{
$sql = "select cat_id,cat_name,cat_total";
if ($language!="eng")
{
	$lang_cat="lang_" . $language;
	$sql.=",$lang_cat";
}
if (!empty($_SESSION["la"]) AND $set_multilang_cat)
{
	$lang_cat = "lang_" . $_SESSION["la"];
	if ($lang_cat!="lang_eng")
		$sql.=",$lang_cat";

}
$sql.= " from $cat_tbl where cat_allow_ads='on' AND cat_fatherid=$lCatFatherID";
$sql = $sql . " order by cat_full_name";
$res = q($sql);

while ($catr=mysql_fetch_array($res))
{
	$catid_sel = $catr["cat_id"];
	$catname = $catr["cat_name"];
	if ($lang_cat)
  	{
  		if (!empty($catr["$lang_cat"]))
  			$catname = $catr["$lang_cat"];
  	}

	$cat_list.= "<option value='$catid_sel'";
	if ($lCatId == $catid_sel)
	{
		$cat_list.= " selected";
	}
	if (!$catr["cat_total"])
		$num_ads=0;
	else 
		$num_ads=$catr["cat_total"];

	$cat_list.= ">$catname ($num_ads) </option>";
}
}	
$tplItem->assign("cat_list",$cat_list);


$tplItem->display("item.tpl");
if (!$admin_area)
{
include_once("member_footer.php");
include_once("footer_inc.php"); 
}
?>

 

 

As revraz stated, the idea is to cycle through the categories, which are no doubt stored in your database. It looks like $option_list is already a generated string of options, so there's already a query and a loop for that in your code somewhere.  All you need to do is follow that example, except with checkboxes instead of option tags.  Or if you were wanting to replace the dropdown with the checkboxes, just alter that code (also remove the select tags where the generated $option_list string is echoed, obviously).

 

Thing is though, I'm not seeing anything in item.php where the option values are being assigned to $option_list, so you're going to have to look somewhere else.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.