Tuesday, May 14, 2013

Form submission to 2 tables using forign key


Form submission

Module -> phpfox_sample -> Template -> Default -> Controller
usersubmit.html.php

<form name="form" method="post" action="{url link='product.usersubmit'}" enctype="multipart/form-data">
Name : <input type="text" name="val[name]"> <br><br>
Content : <input type="text" name="val[content]"><br><br>
<input type="submit" name="val[submit]" > </br>
</form>
{if isset($return)}
<br><br>
successfully Added<br><br>
User id : {$return.id}<br>
Privacy : {$return.privacy}
{/if}<br><br>


Module -> phpfox_sample -> Include -> Component -> Controller
userdisplay.class.php

class Product_Component_Controller_Usersubmit extends Phpfox_Component
{
public function process()
{
if($aVals = $this->request()->get('val')){
unset($aVals['submit']);
// d($aVals);
// exit();
$return = Phpfox::getService('product.usersubmit')->insert($aVals);
// $id = $return['id'];
// $privacy= $return['privacy'];
//$this->template()->assign(array('id'=>$id,'privacy'=>$privacy));
$this->template()->assign(array('return'=>$return));
}
}
}


Module -> phpfox_sample -> Include -> Service
userdisplayservice.class.php

class Product_Service_Usersubmit extends Phpfox_Service
{
/**
*function to insert value to database (two tables)
* @param type $argument
* @return type id, privacy
* @author Arun george <arun@arun-g.in>
* @since 22-11-2012
*
*/
function insert($argument)
{
$nameArray['name'] = $argument['name'];
$id =
$this->database()->insert(Phpfox::getT('newuser'),$nameArray);
$contentArray['content'] = $argument['content'];
$contentArray['privacy'] = $id;
$privacy = \
$this->database()->insert(Phpfox::getT('usercontent'),$contentArray);
$return['id'] = $id;
$return['privacy'] = $privacy;
return $return ;
}
}

Displaying values from DataBase based on some Conditions...


View

module -> phpfox_sample -> Template -> Default -> Controller
userdisplay.html.php
<form name="form2" method="post" action="{url link='product.userdisplay'}"
enctype="multipart/form-data">
Name : <select name="val[user_id]">
<option value="0">select </option>
{foreach from=$userdetails name=userdetail item=detailName}
<option value="{$detailName.u_id}">{$detailName.name} </option>
{/foreach}
</select>
<input type="submit" name="val[submit]" > </br>
</form>
<table style="border: 1px solid #0088CC; width: 500px; ">
{foreach from=$details name=detail item=detailValue}
<tr style="border: 1px solid #0088CC;">
<td style="border-right: 1px solid #0088CC;">{$detailValue.content}</td>
<td style="border-right: 1px solid #0088CC;">{$detailValue.privacy}</td>
</tr>
{/foreach}
</table>

module -> phpfox_sample -> Include -> Component -> Controller
userdisplay.class.php

class Product_Component_Controller_Userdisplay extends Phpfox_Component
{
$userdetails =
Phpfox::getService('product.userdisplayservice')->getUser();
if($userdetails)
$this->template()->assign(array('userdetails'=>$userdetails));
public function process()
{
if($aVals = $this->request()->get('val'))
{
unset($aVals['submit']);
$details = Phpfox::getService('product.userdisplayservice')->get($aVals);
if($details)
$this->template()->assign(array('details'=>$details));
}
}
}

module -> phpfox_sample ->Include -> Service
userdisplayservice.class.php

class Product_Service_Userdisplayservice extends Phpfox_Service
{
/**
*Function to get rows from table
* @return type
* @author Arun George <arun@arun-g.in>
* @since 20-11-2012
*/
function getUser()
{
$uname = $this->database()->select('*')
->from(Phpfox::getT('newuser'))
->execute('getSlaveRows');
// d($row);
return $uname;
}
/**
*Function to get rows from table
* @return type
* @author Arun George <arun@arun-g.in>
* @since 20-11-2012
*/
function get($aVals)
{
// d($aVals);
// exit();
//
$cond = '';
if($aVals['user_id']==1)
{
$cond = ' r.privacy IN(1,2,3)';
}
elseif($aVals['user_id']==2)
{
$cond = ' r.privacy IN(1,2)';
}
elseif($aVals['user_id']==3)
{
$cond = ' r.privacy IN(3)';
}
else{
$cond = ' r.privacy IN(0)';
}
$row = $this->database()->select('r.*')
->from(Phpfox::getT('usercontent'), 'r')
->where($cond)
->execute('getRows');
return $row;
}
}

Simple Form Submission and store value in Database with Display, Delete..


Module -> phpfox_sample -> Template -> Default -> Controller
formsubmit.html.php

<form name="form2" method="post" action="{url link='product.formsubmit'}"
enctype="multipart/form-data">
Name : <input type="text" name="val[name]"> <br>
User Name : <input type="text" name="val[user]"><br>
Password : <input type="password" name="val[pass]"></br>
E-mail : <input type="text" name="val[email]"><br>
<input type="submit" name="val[submit]" > </br>
</form>
<table style="border: 1px solid #0088CC; width: 500px; ">
<tr style="border: 1px solid #0088CC;"">
<td style="border-right: 1px solid #0088CC;">Name</td>
<td style="border-right: 1px solid #0088CC;">User</td>
<td style="border-right: 1px solid #0088CC;">E-mail</td>
<td></td>
</tr>
{foreach from=$details name=detail item=detailValue}
<tr id="delete_{$detailValue.id}" style="border: 1px solid #0088CC;">
<td style="border-right: 1px solid #0088CC;">{$detailValue.name}</td>
<td style="border-right: 1px solid #0088CC;">{$detailValue.user}</td>
<td style="border-right: 1px solid #0088CC;">{$detailValue.email}</td>
<td> <a href="#" onclick = "$.ajaxCall('product.delete', 'id={$detailValue.id}');"
> DELETE </a> </td>
</tr>
{/foreach}
</table>

module -> phpfox_sample -> Include -> Component -> Controller
formsubmit.class.php

class Phpfoxsample_Component_Controller_Forminsert extends Phpfox_Component
{
/**

* @author Arun George <arun@arun-g.in>
* @since 19-11-2012

*/
public function process()
{
//$this->template()->assign(array('members'=>$aMembers,'id'=>$id,'aPages'=>
$aPage,'currentUser'=>$currentUser));
if($aVals = $this->request()->get('val')){
unset($aVals['submit']);
//d($aVals); exit();
//Phpfox::getService('forminsertservice')->test($aVals);
Phpfox::getService('phpfoxsample.forminsertservice')->insert($aVals);
}
$details = Phpfox::getService('phpfoxsample.forminsertservice')->get();
$this->template()->setTitle('My First Form Posting');
if($details)
$this->template()->assign(array('details'=>$details));
}
}

Module -> phpfox_sample -> Include -> Service
formsubmit.class.php

class Product_Service_Formsubmit extends Phpfox_Service
{
/**
*function to insert value to database
* @param type $argument
* @return type id
* @author Arun George <arun@arun-g.in>
* @since 19-11-2012
*
*/
function insert($argument)
{
//d($argument);
//exit();
$id = $this->database()->insert(Phpfox::getT('formsubmit'), $argument);
return $id ;
}
/**
*Function to get rows from table
* @return type
* @author Arun George <arun@arun-g.in>
* @since 19-11-2012
*/
function get()
{
$row = $this->database()->select('*')
->from(Phpfox::getT('formsubmit'))
->execute('getSlaveRows');
// d($row);
return $row;
}
/**
* function to delete the entry from database
* @param type $id
* @author Arun George <arun@arun-g.in>
* @since 19-11-2012
*
*/
function delete($id)
{
$this->database()->delete(Phpfox::getT('formsubmit'), ' id = ' . (int) $id);
return true;
}
}

module -> phpfox_sample -> Include -> Component -> Ajax
ajax.class.php

/**
* [PHPFOX_HEADER]
*/
defined('PHPFOX') or exit('NO DICE!');
class Product_Component_Ajax_Ajax extends Phpfox_Ajax
{
/**
* Function to delete value using Ajax
* @author Arun George <arun@arun-g.in>
* @since 19-11-2012
*/
function delete()
{
$id = $this->get('id');
$return = Phpfox::getService('product.formsubmit')->delete($id);
$this->hide("#delete_".$id);
$this->alert('deleted');
}
}

Phpfox - Creating Your First Add-on : Creating A Module & Controller


Creating A Module

Extension >> Module >> Create New Module

Product : PhpFox Sample Product
Module ID: phpfox_sample better to place the name of product id itself
Add to Menu: YES
Sub Menu: Fill it if needed drop down menu’s
Info : Short discription about module

Then go to the folder structure and create

Module -> phpfox_sample

/include/
/include/component/
/include/component/ajax/
/include/component/block/
/include/component/controller/
/include/plugin/
/include/service/
/static/
/static/css/default/default/
/static/image/
/static/jscript/
/template/
/template/default/
/template/default/block/
/template/default/controller/

Creating a Controller

Controllers are PHP classes that control all the pages on phpFox.

module ->phpfoxsample -> include -> component -> controller
index.class.php

Phpfox - Creating Your First Add-on : Creating a Product


Creating a Product

Every Module or plugin in phpfox must belong to a product. Everything you create within the AdminCP requires that it be part of a product. All the menus, phrases, settings etc... that is provided with the script when you first install it is part of our product, which has the unique ID phpfox.

Log into your AdminCP and navigate to:

Extensions >> Product >> Create New Product

Product ID: unique product ID , must be lowercase ,
Name it as: phpfox_sample

Title : Title to display the product
Name it as : PhpFox Sample Product

Description :
Name it as : This is a sample product

Version :3.1
Product URL : ###.Com
Version Check URL : ###.com
Active : YES

SUBMIT

PHPFOX Knowledgebase


Follow this link to know more about Phpfox Installation, Upgrading, Admin Guide, editing css, templates, etc.. http://www.phpfox.com/kb/

(Only registered user can access the knowledgebase).

Knowledgebase will show you the below details

1). Getting Started with phpFox
       Installing the Product
       Upgrading the Product from v2 to v3
       Upgrading the Product
       Short URLs & Rewrite Rules
       Install Branding Removal

2). Administrator Guide
       Storing Images, Videos & Songs on Separate Servers (Phpfox CDN)
       Disable or enable a module (feature) - CMS
       Change site SEO settings.
       Change references to Phpfox (email signature, site name, site logo, etc)
       Enabling Facebook Connect

3). Design and Template
       Editing Your Sites CSS
       Editing Your Sites Templates
       Creating your site's looks
       Change your site's logo

4). AdminCP User Guide
5). Developer Documentation

I will describe something which comes under this developer documentation.

PHPFOX


PhpFox is a social network software that gives you the ability to create a unique community that includes many of the features found on sites like Facebook and MySpace.

PhpFox is a leading provider in social networking software that today powers thousands of communities that range from all sort of niche's and business models.

To learn more about phpFox and its features, please visit Phpfox features page http://www.phpfox.com/features/.
To view a demo of phpFox, please visit phpfox live demo http://www.phpfox.com/demos/.
If you would like to see phpFox live and in action you can find some of our clients communities from a simple google search.

History
Raymond Benc founded phpFox July 2005, which is when version 1.0.3 was released. Very first public release. Development of the first versions of phpFox took place in 2004, while Raymond was working on his own personal social network. During the development of phpFox Raymond saw the need from others to want to open their own social network and shifted his development of the product towards the public.
Our entire team is located all over the globe, which allows us to keep in touch with all of our clients within their respective time zones.
phpFox Inc. is a privately held company registered in Delaware, United States and Benc Enterprises AB is a privately held company registered in Sweden.
Start your social network today and learn why phpFox is "The Future of Social Networking".

-------------------------
I am Arun G. Currently I am working in PHPFOX project.
I would like to share some of my knowledge in phpfox with you, please follow my upcoming posts with label 'phpfox and arun-g'. I am posting this article without any profit intention. If anyone found any problem with this article, please let me know. I will remove the posts.

phpfox software packages is a paid one. Before you start using this software you should purchase it, follow the link. http://www.phpfox.com/pricing/

*---------------------------------------------------*