On the frontpage there is a chat box with text in it (divider id #frontpage-message). We would like to make this dynamic so any admin can change that text on a page in the Administration section. Please be sure to limit the amount of characters a user can input so it does not allow enough text to overflow from the chatbox.
to write the page title and set the url
[code]
else if($type=='CHM')
{
$external_page_title = elgg_echo('expages:CHM');
}
[/code]
code to generate the form for handling the messages
[code]
/* ds start - CHM */
if($type=="CHM")
{
$msg = "Edit the Frontpage welcome Message here. <br /><br />";
$chatMessageForm = <<<EOT
<form method="post" action="">
<label for="chatMsg">
Customize the Front Page Chat Message Here. [Max : 50 characters]
</label>
<textarea id="chatMsg" name="chatMsg" rows="5" cols="25">$msgNow</textarea>
<br />
<input type="submit" name="chmsubmit" value="Update" />
</form>
EOT;
echo $chatMessageForm;
$form_body = $msg;
}
/* ds END - CHM */
[/code]
code to save the new message to the database
[code]
/* ds new - 10.02.2011 */
/* save the new message to the database*/
if(isset($_POST["chatMsg"]))
{
$newMsg = substr(addslashes(mysql_real_escape_string($_POST["chatMsg"])),0,50);
$isTableFound = 0;
$tables = mysql_list_tables ($CONFIG->dbname);
while (list ($temp) = mysql_fetch_array ($tables))
{
if ($temp == $tableName)
{
$isTableFound = 1;
break;
}
else
$isTableFound = 0;
}
if($isTableFound == 0)
{
$tblCreateQuery = "CREATE TABLE `{$CONFIG->dbname}`.`{$tableName}` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`msg` VARCHAR( 150 ) NOT NULL ,
`dt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
PRIMARY KEY ( `id` )
) ENGINE = InnoDB ";
$tableResult = mysql_query($tblCreateQuery);
if($tableResult)
{
$insertMsgQuery = "INSERT INTO ".$tableName." VALUES('".$newMsg."')";
$insResult = mysql_query($insertMsgQuery);
}
else
echo "table creation failure";
}
else
{
$updateMsgQuery = "UPDATE {$tableName} SET msg='".$newMsg."' WHERE id=1";
$insResult = mysql_query($updateMsgQuery);
}
echo "<strong>Message Updated Successfully<strong>";
}
}
$msgQuery = "SELECT msg FROM {$tableName} WHERE id=1";
$result = mysql_query($msgQuery);
$row = mysql_fetch_row($result);
$msgNow = stripslashes($row[0]);
/* ds new - 10.02.2011 */
[/code]
Comments
Post a Comment