Jump to content

Explain this code pls


stbalaji2u

Recommended Posts

im trying to working on a template based document building script.i think this code will help me to get a input from the user such that he dont need to type the full document just the name,places of his choice must be selected and our script will generate the final document with his needed text in the placeholder like {name} {place} etc.

 

the code is here.pls tell me for what this code exactly for? and of these two codes which will best suit my need?

 

$Sdocbuild->db_Query( "INSERT INTO `$tem_table` (`Template`) VALUES ('".$_POST['New_Template']."')" );

 

second code is

 

 $SkaLinks->db_Query( "UPDATE `$tem_table` SET `Template`='".$_POST['Letter_tem'][$value]."' WHERE `ID`='".$value."'" );

thanks.

Link to comment
https://forums.phpfreaks.com/topic/136702-explain-this-code-pls/
Share on other sites

ok then here is the code.

im using this as a model to make a script that displays a template text and when the user select a word from a drop down list box then that word must be replaced in the placeholder text like {name} .

<?php

require_once( '../headers.php' );	

// Process input data

$cat_id = ( $_GET['cat_id'] ) ? ( int )$_GET['cat_id'] : ( int )$_POST['cat_id'];

if ( strlen( trim( $_POST['New_Template'] ) ) )
{
$tem_attribute  = 1;
}


// TODO : Statements here

$smarty		= new DirSmarty();
$ADMIN = $SkaLinks->IsAdmin();

if ( $ADMIN['Type'] != 2 )
{
$msg = $_skalinks_lang['msg']['not_admin'];
require_once( '../index.php' );
}
else
{
$tem_table = $SkaLinks->m_LetterTemTable;
$tem_binding_table = $SkaLinks->m_LetterTemBindingTable;
$links_table = $SkaLinks->m_LinksTable;
if ( $_POST['Add_Template'] )
{
	if ( $tem_attribute )
	{
		$SkaLinks->db_Query( "INSERT INTO `$tem_table` (`Template`) VALUES ('".$_POST['New_Template']."')" );
		$msg = $_skalinks_lang['msg']['template_added'];	
	}
	else
	{
		$msg = $_skalinks_lang['msg']['inf_incomplete'];
	}
}
if ( $_POST['Change_Template'] )
{
	if ( $_POST['Templates_arr'] )
	{
		$tem_info_attr = 0;
		foreach( $_POST['Templates_arr'] as $value )
		{
			if ( strlen( trim( $_POST['Letter_tem'][$value] ) ) )
			{
				$SkaLinks->db_Query( "UPDATE `$tem_table` SET `Template`='".$_POST['Letter_tem'][$value]."' WHERE `ID`='".$value."'" );
			}
			else
			{
				$tem_info_attr = 1;
			}
		}
		if ( count( $_POST['Templates_arr'] ) > 1 && $tem_info_attr )
		{
			$msg = $_skalinks_lang['msg']['templates_not_all_changed'];
		}
		elseif ( $tem_info_attr )
		{
			$msg = $_skalinks_lang['msg']['template_not_changed'];
		}
		else
		{
			$msg = $_skalinks_lang['msg']['template_changed'];
		}
	}
	else
	{
		$msg = $_skalinks_lang['msg']['tem_not_checked'];
	}
}

if ( $_POST['Delete_Template'] )
{
	if ( $_POST['Templates_arr'] )
	{
		foreach( $_POST['Templates_arr'] as $key => $value )
		{
			$tem_status = $SkaLinks->db_Row( "SELECT `Status` FROM `$tem_table` WHERE `ID`='".$_POST['Templates_arr'][$key]."'" );
			if ( !$tem_status['Status'] )
			{
				$SkaLinks->db_Query( "DELETE FROM `$tem_table` WHERE `ID`='".$_POST['Templates_arr'][$key]."'" );
				$SkaLinks->db_Query( "DELETE FROM `$tem_binding_table` WHERE `Template_id`='".$_POST['Templates_arr'][$key]."'" );
				$SkaLinks->db_Query( "UPDATE `$links_table` SET `Template_id`='0' WHERE `Template_id`='".$_POST['Templates_arr'][$key]."'" );
			}
			else
			{
				$msg = $_skalinks_lang['msg']['del_default_template'];
			}
		}

		$msg = ( !$msg ) ? $_skalinks_lang['msg']['template_deleted'] : $msg;
	}
	else
	{
		$msg = $_skalinks_lang['msg']['tem_not_checked'];
	}
}
$_output['all_templates']		 = $SkaLinks->db_Fetch( "SELECT * FROM `$tem_table`" );
$_output['count']			 = 0;
// Show HTML

display( 'template_settings' );
}
?>

 

I want to have a text field that shows text like

 

Hi my name is {name} ,im living in {place}.i finished masters in {degree}.Im now going to {destination}.

 

and now below this text box there are 4 drop down boxes one is {name} ,and for {place} and for {degree} and for {destination}

all these drop down boxes have multiple values for example

{name} list box contains options like gevans,corey,jackson etc

now if he selects the name gevans then the next page(i.e page that comes after clicking submit button) must show the replaced texts and now it will become a easily made document.

hope this is sufficient if you want to know more details pls dont hesitate to ask me.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.