Location: PHPKode > projects > chillyCMS > chillyCMS/modules/guestbook/backend.php
<?php
defined('DOIT') or die('Restricted access');

global $page;
$mainmodid=intval($_REQUEST["id"]);
$settingsarray=explode(',', $modsettings);
//if it was a new content, use standard settings
if ($settingsarray[0]==0 && $settingsarray[1]==2 && sizeof($settingsarray)==2) {
	$settingsarray=array(1,"",1,1,1,1,1,"","");
}

if (isset($_POST["actives"]) && $_POST["actives"]!=null) {
	$sql="update mod_guestbook set active=0 where mainmodid=$mainmodid";
	$page->query($sql);
	$sql="update mod_guestbook set active=1 where mainmodid=$mainmodid and (id=";
	$sql.=implode(" or id=",$_POST["actives"]);
	$sql.=")";
	$page->query($sql);
}
//delete something?
if (isset($_GET["action"]) && $_GET["action"]=="delete") {
	$delid=intval($_GET["entry"]);
	if ($delid>0) {
		$sql="delete from mod_guestbook where id=$delid";
		$page->query($sql);
	}
}
$editform .= "<p>$mod_gb[lbl_modgb]</p><br />\n";
if ($writeright) {
	$editform .= "<fieldset style='padding:5px; border:solid 1px #000; margin:0;'>\n";
	//only show email is compulsory if email is displayed!
	$editform .= "<script type='text/javascript' language='javascript'>
	function checkvalue() {
		if(document.getElementById('yes').checked == true) {
			document.getElementById('gb_tr_requiremail').style.display = 'table-row';
		} else {
			document.getElementById('gb_tr_requiremail').style.display = 'none';
			document.getElementById('requirenot').checked = true;
		}
	}
	</script>";
	//publish new entries?
	$checkyes=$checkno="";
	if($settingsarray[0]==1) { $checkyes=" checked='checked'"; } else { $checkno=" checked='checked'"; }
	$editform .= "<table id='gb_table_backend' cellspacing='5'>\n".
	"<tr>\n".
	"<td class='right'>$mod_gb[lbl_publish]</td>\n".
	"<td><input type='radio' name='notificationmail' value='1'$checkyes />$l_gen[lbl_yes]</td>\n".
	"<td><input type='radio' name='notificationmail' value='0'$checkno />$l_gen[lbl_no]</td>\n".
	"</tr>\n";
	//notification email(s)
	$editform .= "<tr>\n".
	"<td class='right'>$mod_gb[lbl_notific]</td>\n".
	"<td colspan='2'><textarea name='adminemail' cols='25' rows='3'>$settingsarray[1]</textarea></td>\n".
	"</tr>\n".
	"<tr style='line-height:12px;'>\n".
	"<td></td><td colspan='2' style='font-size:10px;'>$mod_gb[lbl_separate]</td>\n".
	"</tr>\n";
	//show email?
	$checkyes=$checkno="";
	if($settingsarray[2]==1) { $checkyes=" checked='checked'"; } else { $checkno=" checked='checked'"; }
	$editform .= "<tr>\n".
	"<td class='right'>$mod_gb[lbl_showmail]</td>\n".
	"<td><label onclick='javascript:checkvalue()'>".
	"<input id='yes' type='radio' name='showemail' value='1'$checkyes />$l_gen[lbl_yes]</label></td>\n".
	"<td><label onclick='javascript:checkvalue()'><input id='no' type='radio' name='showemail' value='0'$checkno />$l_gen[lbl_no]".
	"</label></td>\n".
	"</tr>\n";
	//email adress is required?
	$checkyes=$checkno="";
	if($settingsarray[3]==1) { $checkyes=" checked='checked'"; } else { $checkno=" checked='checked'"; }
	$editform .= "<tr id='gb_tr_requiremail'>\n".
	"<td class='right'>$mod_gb[lbl_reqmail]</td>\n".
	"<td><input type='radio' name='requiremail' value='1' $checkyes />$l_gen[lbl_yes]</td>\n".
	"<td><input id='requirenot' type='radio' name='requiremail' value='0' $checkno />$l_gen[lbl_no]".
	"<script type='text/javascript' language='javascript'>checkvalue();</script>\n".
	"</td>\n".
	"</tr>\n";
	//new entries first?
	$checkyes=$checkno="";
	if($settingsarray[4]==1) { $checkyes=" checked='checked'"; } else { $checkno=" checked='checked'"; }
	$editform .= "<tr>\n".
	"<td class='right'>$mod_gb[lbl_newfirst]</td>\n".
	"<td><input type='radio' name='newestpostingfirst' value='1'$checkyes />$l_gen[lbl_yes]</td>\n".
	"<td><input type='radio' name='newestpostingfirst' value='0'$checkno />$l_gen[lbl_no]</td>\n".
	"</tr>\n";
	//captcha
	$checkyes=$checkno="";
	if($settingsarray[5]==1) { $checkyes=" checked='checked'"; } else { $checkno=" checked='checked'"; }
	$editform .= "<tr>\n".
	"<td class='right'>$mod_gb[lbl_captcha]</td>\n".
	"<td><label onclick='javascript:checkcaptcha()'><input id='captchayes' type='radio' name='captcha' ".
	"value='1'$checkyes />$l_gen[lbl_yes]</label></td>\n".
	"<td><label onclick='javascript:checkcaptcha()'><input id='captchano' type='radio' name='captcha' ".
	"value='0'$checkno />$l_gen[lbl_no]</label></td>\n".
	"</tr>\n";
	//allow guests?
	$checkyes=$checkno="";
	if($settingsarray[6]==1) { $checkyes=" checked='checked'"; } else { $checkno=" checked='checked'"; }
	$editform .= "<tr>\n".
	"<td class='right'>$mod_gb[lbl_guests]</td>\n".
	"<td><input type='radio' name='allowguests' value='1'$checkyes />$l_gen[lbl_yes]</td>\n".
	"<td><input type='radio' name='allowguests' value='0'$checkno />$l_gen[lbl_no]</td>\n".
	"</tr>\n".	
	"</table>\n".
	"</fieldset>\n";
} else {
	$editform .= $l_edit["msg_nowrite"];
}
//entries
if ($writeright) {
	$editform .= "</div>\n".
	"<table cellpadding='5px' cellspacing='0' width='100%' style='margin: 20px 0;clear:both;'>\n".
	"<tr>\n".
	"<th class='center'>$mod_gb[lbl_date]</th>\n".
	"<th class='center'>$mod_gb[lbl_name]</th>\n".
	"<th class='center'>$mod_gb[lbl_msg]</th>\n".
	"<th class='center'>$mod_gb[lbl_comment]?</th>\n".
	"<th class='center'>$l_gen[lbl_edit]</th>\n".
	"<th class='center'>$l_gen[lbl_email]</th>\n".
	"<th class='center'>$mod_gb[lbl_published]</th>\n".
	"<th class='center'>$l_gen[lbl_delete]</th>\n".
	"</tr>\n";
	//Show entries
	$sql="select * from mod_guestbook where mainmodid=$mainmodid order by msg_date desc";
	$page->query($sql);
	$result = $page->db->getdata_array();
	//$result=db_query_array($sql);
	if(!empty($result)) {
		$style="odd";
		foreach($result as $row) {
			//is the item active?
			$editform .= "<input type='hidden' name='actives[]' value='0'/>\n";
			if ($row["active"]==1) { $active="<input type='checkbox' name='actives[]' checked='checked' value='$row[id]'/>\n"; }
			else { $active="<input type='checkbox' name='actives[]' value='$row[id]'/>\n"; }
			//is there a reply?
			if ($row["reply"]!=null) { $reply="<a class='ok'></a>\n"; }
			else { $reply="<a class='cancel'></a>\n"; }
			//shorten message
			$message=$row["message"];
			if (strlen($message)>20) { $message=substr($message,0,20)."..."; }
			//make edit link
			$editlink="<a target='popup' onclick=\"window.open('','popup','width=600,height=400,scrollbars=yes,".
			"toolbar=no,status=no,resizable=no,menubar=no,location=no,directories=no,top=200,left=150')\" ".
			"href='".URL."/modules/guestbook/editgbentry.php?id=$row[id]' class='edit' title='$l_gen[lbl_edit]'></a>\n";
			//row output
			$editform .= "<tr class='$style'>\n".
			"<td>".$row["msg_date"]."</td>\n".
			"<td>".$row["name"]."</td>\n".
			"<td>$message</td>\n".
			"<td>$reply</td>\n".
			"<td>$editlink</td>\n".
			"<td>".$row["email"]."</td>\n".
			"<td>".$active."</td>\n".
			"<td><a class='delete' href='edit.site.php?id=$mainmodid&amp;action=delete&amp;entry=$row[id]' ".
			"title='$l_gen[lbl_delete]'></a></td>\n".
			"</tr>\n";
			if($style=="odd") { $style="even"; } else { $style="odd"; }
		}
	}
	$editform .= "</table>\n".
	"<div>\n";
}
//since the data is to be saved in an array, the order is important!
$specialsettings="notificationmail,adminemail,showemail,requiremail,newestpostingfirst,captcha,allowguests,publickey,privatekey";
?>
Return current item: chillyCMS