Saturday, September 29, 2012

Difference between session_register and $_SESSION[] in phpsession_register and $_SESSION[] in php




We can use either session_register or $_SESSION for registering session variable in php.

Find below the difference between both of them. 


session_register() is a function and $_SESSION is a superglobal array.

session_register() is used to register a session variable and it works only when register_globals is turned on. (Turning ON register_globals will create mesh-ups, but some applications (e.g OScommerce) requires turning ON of register_globals)
But $_SESSION works even when register_globals is turned off.

If session_start() was not called before session_register() is called, an implicit call to session_start() with no parameters will be made. But $_SESSION requires session_start() before use.

session_register function returns boolean value and $_SESSION returns string value

session_register() function has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0.


We know that Webpages are getting displayed using stateless Protocol.
So there should be someway for keeping the session of the user navigating the webpages within a website.

Session variables and Cookie variables can be used for this purpose.
Basically Session variables are maintained by webserver. (i-e)Physically the value of any Session variable will be written to a file located in the web server.

In php, we can set/use the session variable using $_SESSION. Say for example, if we need to put the user email (e.g $email) in session, we can use it as $_SESSION['email'] whose value should be set as $_SESSION['email']=$email.

Whenever assigning this session variable, a file will be written to the web server at location specified by session_path variable in php.ini file.

Suppose 1000 users are using your website, there will be 1000 files created for storing one session variable.

So it will become a big memory issue if you are not managing the session properly. (i-e) we should unset the session variables during logout. Appropriate session timeout value should be specified to enable automatic expiration of the session if the user forgets to logout. And also we need to take additional care to manage session if security is more important for your website.

Or alternatively we can use cookie variables which are stored by the web browser in the users machine. As the cookie variables are stored in the client machine, it can be available till it gets deleted either by browser setting, or by the code or by the user manually.

Since cookie variables can live even after closing the browser session, it can be very useful for improving user experience. (i-e) Lot of data related to user preferences can be stored in the cookie. So whenever the same user logs in, his previous settings can be applied automatically by using these cookie values. For example if the user allows the website to store his password in cookie variable, he can log in to the website without typing his password again.

In php, cookie variables can be set using setcookies function. 
But anyway, privacy is important for you, you can restrict the cookies by changing the browser settings.
More Articles...

Thursday, September 27, 2012

PHP and MySQL Stored Procedure Exec Problem

  • <?php
  • $Server = "127.0.0.1";
  • $DataBase = "tedt";
  • $UserName = "root";
  • $PassWord = "124@#";
  • $Conn = mysqli_connect($host, $UserName, $PassWord);
  • if(!$Conn)
  • {
  • die("Could not connect to server : " . mysqli_error());
  • }
  • else
  • {
  • mysqli_select_db($Conn,$DataBase) or die("Could not connect to database");
  • }
  • ?>
  • <?php
  • print "Procedure #1";
  • $res= $Conn->query("CALL storepro;");
  • print_r($res) ;
  • ?>

    Monday, September 24, 2012

    json using php tutorial

    After reading this post, you will be able to understand, work and test JSON code with PHP.
    There are already lots of tutorials out there on handling JSON with PHP, but most of them don't go much deeper than throwing an array against json_encode and hoping for the best. This article aims to be a solid introduction into JSON and how to handle it correctly in combination with PHP. Also, readers who don't use PHP as their programming language can benefit from the first part that acts as a general overview on JSON.
    JSON (JavaScript Object Notation) is a data exchange format that is both lightweight and human-readable (like XML, but without the bunch of markup around your actual payload). Its syntax is a subset of the JavaScript language that was standardized in 1999. If you want to find out more, visit the official website.
    The cool thing about JSON is that you can handle it natively in JavaScript, so it acts as the perfect glue between server- and client-side application logic. Also, since the syntactical overhead (compared to XML) is very low, you need to transfer less bytes of ther wire. In modern web stacks, JSON has pretty much replaced XML as the de-factor payload format (aside from the Java world I suppose) and client side application frameworks like backbone.js make heavy use of it inside the model layer.
    Before we start handling JSON in PHP, we need to take a short look at the JSON specification to understand how it is implemented and what's possible.

    Introducing JSON

    Since JSON is a subset of the JavaScript language, it shares all of its language constructs with its parent. In JSON, you can store unordered key/value combinations in objects or use arrays to preserve the order of values. This makes it easy to parse and to read, but also has some limitations. Since JSON only defines a small amount of data types, you can't transmit types like dates natively (you can, but you need to transform them into a string or a unix timestamp as an integer).
    So, what datatypes does JSON support? It all boils down to strings, numbers, booleans and null. Of course, you can also supply objects or arrays as values.
    Here's a example JSON document:
    1. {
    2. "title": "A cool blog post",
    3. "clicks": 4000,
    4. "children": null,
    5. "published": true,
    6. "comments": [
    7. {
    8. "author": "Mister X",
    9. "message": "A really cool posting"
    10. },
    11. {
    12. "author": "Misrer Y",
    13. "message": "It's me again!"
    14. }
    15. ]
    16. }
    It contains basically everything that you can express through JSON. As you can see no dates, regexes or something like that. Also, you need to make sure that your whole JSON document is encoded in UTF-8. We'll see later how to ensure that in PHP. Due to this shortcomings (and for other good reasons) BSON(Binary JSON) was developed. It was designed to be more space-efficient and provides traversability and extensions like the date type. Its most prominent use case is MongoDB, but honestly I never came across it somewhere else. I recommend you to take a short look at the specification if you have some time left, since I find it very educating.
    Since PHP has a richer type handling than JSON, you need to prepare yourself to write some code on both ends to transform the correct information apart from the obligatory encoding/decoding step. For example, if you want to transport date objects, you need to think if you can just send a unix timestamp over the wire or maybe use a preformatted date string (like strftime).

    Encoding JSON in PHP

    Some years ago, JSON support was provided through the json pecl extension. Since PHP 5.2, it is included in the core directly, so if you use a recent PHP version you should have no trouble using it.
    Note: If you run an older version of PHP than 5.3, I recommend you to upgrade anyway. PHP 5.3 is the oldest version that is currently supported and with the latest PHP security bugs found I would consider it critical to upgrade as soon as possible.
    Back to JSON. With json_encode, you can translate anything that is UTF-8 encoded (except resources) from PHP into a JSON string. As a rule of thumb, everything except pure arrays (in PHP this means arrays with an ordered, numerical index) is converted into an object with keys and values.
    The method call is easy and looks like the following:
    1. json_encode(mixed $value, int $options = 0);
    An integer for options you might ask? Yup, that's called a bitmask. We'll cover them in a separate part a little bit later. Since these bitmask options change the way the data is encoded, for the following examples assume that we use defaults and don't provide custom params.
    Let's start with the basic types first. Since its so easy to grasp, here's the code with short comments on what was translated:
    1. <?php
    2. // Returns: ["Apple","Banana","Pear"]
    3. json_encode(array("Apple", "Banana", "Pear"));
    4.  
    5. // Returns: {"4":"four","8":"eight"}
    6. json_encode(array(4 => "four", 8 => "eight"));
    7.  
    8. // Returns: {"apples":true,"bananas":null}
    9. json_encode(array("apples" => true, "bananas" => null));
    10. ?>
    How your arrays are translated depends on your indexes used. You can also see that json_encode takes care of the correct type conversion, so booleans and null are not transformed into strings but use their correct type. Let's now look into objects:
    1. <?php
    2. class User {
    3. public $firstname = "";
    4. public $lastname = "";
    5. public $birthdate = "";
    6. }
    7.  
    8. $user = new User();
    9. $user->firstname = "foo";
    10. $user->lastname = "bar";
    11.  
    12. // Returns: {"firstname":"foo","lastname":"bar"}
    13. json_encode($user);
    14.  
    15. $user->birthdate = new DateTime();
    16.  
    17. /* Returns:
    18.   {
    19.   "firstname":"foo",
    20.   "lastname":"bar",
    21.   "birthdate": {
    22.   "date":"2012-06-06 08:46:58",
    23.   "timezone_type":3,
    24.   "timezone":"Europe\/Berlin"
    25.   }
    26.   }
    27. */
    28. json_encode($user);
    29. ?>
    Objects are inspected and their public attributes are converted. This happens recursively, so in the example above the public attributes of the DateTime object are also translated into JSON. This is a handy trick if you want to easly transmit datetimes over JSON, since the client-side can then operate on both the actual time and the timezone.
    1. <?php
    2. class User {
    3. public $pub = "Mister X.";
    4. protected $pro = "hidden";
    5. private $priv = "hidden too";
    6.  
    7. public $func;
    8. public $notUsed;
    9.  
    10. public function __construct() {
    11. $this->func = function() {
    12. return "Foo";
    13. };
    14. }
    15. }
    16.  
    17. $user = new User();
    18.  
    19. // Returns: {"pub":"Mister X.","func":{},"notUsed":null}
    20. echo json_encode($user);
    21. ?>
    Here, you can see that only public attributes are used. Not initialized variables are translated to null while closures that are bound to a public attribute are encoded with an empty object (as of PHP 5.4, there is no option to prevent public closures to be translated).

    The $option bitmasks

    Bitmasks are used to set certain flags on or off in a function call. This language pattern is commonly used in C and since PHP is written in C this concept made it up to some PHP function arguments as well. It's easy to use: if you want to set an option, just pass the constant as an argument. If you want to combine two or more options, combine them with the bitwise OR operation |. So, a call to json_encode may look like this:
    1. <?php
    2. // Returns: {"0":"Starsky & Hutch","1":123456}
    3. json_encode(array("Starsky & Hutch", "123456"), JSON_NUMERIC_CHECK | JSON_FORCE_OBJECT);
    4. ?>
    JSON_FORCE_OBJECT forces the array to be translated into an object and JSON_NUMERIC_CHECK converts string-formatted numbers to actual numbers. You can find all bitmasks (constants) here. Note that most of the constants are available since PHP 5.3 and some of them were added in 5.4. Most of them deal with how to convert characters like < >, & or "". PHP 5.4 provides a JSON_PRETTY_PRINT constant that may you help during development since it uses whitespace to format the output (since it adds character overhead, I won't enable it in production of course).

    Decoding JSON in PHP

    Decoding JSON is as simple as encoding it. PHP provides you a handy json_decode function that handles everything for you. If you just pass a valid JSON string into the method, you get an object of type stdClass back. Here's a short example:
    1. <?php
    2. $string = '{"foo": "bar", "cool": "attr"}';
    3. $result = json_decode($string);
    4.  
    5. // Result: object(stdClass)#1 (2) { ["foo"]=> string(3) "bar" ["cool"]=> string(4) "attr" }
    6. var_dump($result);
    7.  
    8. // Prints "bar"
    9. echo $result->foo;
    10.  
    11. // Prints "attr"
    12. echo $result->cool;
    13. ?>
    If you want to get an associative array back instead, set the second parameter to true:
    1. <?php
    2. $string = '{"foo": "bar", "cool": "attr"}';
    3. $result = json_decode($string, true);
    4.  
    5. // Result: array(2) { ["foo"]=> string(3) "bar" ["cool"]=> string(4) "attr" }
    6. var_dump($result);
    7.  
    8. // Prints "bar"
    9. echo $result['foo'];
    10.  
    11. // Prints "attr"
    12. echo $result['cool'];
    13. ?>
    If you expect a very large nested JSON document, you can limit the recursion depth to a certain level. The function will return null and stops parsing if the document is deeper than the given depth.
    1. <?php
    2. $string = '{"foo": {"bar": {"cool": "value"}}}';
    3. $result = json_decode($string, true, 2);
    4.  
    5. // Result: null
    6. var_dump($result);
    7. ?>

    Tuesday, September 18, 2012

    curl service example in php

    <?php
    
    $ch = curl_init("http://rss.news.yahoo.com/rss/oddlyenough");
    $fp = fopen("example_homepage.html", "w");
    
    curl_setopt($ch, CURLOPT_FILE, $fp);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    
    curl_exec($ch);
    curl_close($ch);
    fclose($fp);
    
    $xml = simplexml_load_file('example_homepage.html');
    print "<ul>\n";
    foreach ($xml->channel->item as $item){
      print "<li>$item->title</li>\n";
    }
    print "</ul>";
    
    ?>

    Monday, September 17, 2012

    function split() is deprecated php and codeingiter , joomla , worpress , magento, php, smarty, cakephp

    replace    $base_struc     = split('[/.-]', 'd/m/Y');  to     $base_struc     = explode('/', 'd/m/Y');

    function split() is deprecated php and codeingiter , joomla , worpress , magento, php, smarty, cakephp

    Sunday, September 16, 2012

    The URI you submitted has disallowed characters. in codeigniter [solve]


    [SOLVE]
    first replace in config.php -$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';  to $config['permitted_uri_chars'] = 'a-z 0-9~%\.\:_\-';

    second - replace from  D:\xampp\htdocs\hes\system\libraries\URI.php
    if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str))

    to
    if ( ! preg_match("|^[".($this->config->item('permitted_uri_chars'))."]+$|i", rawurlencode($str)))

    i think you got my point and then working   good

    codeigniter Deprecated error and A PHP Error was encountered [SOLVE]


    Deprecated: Assigning the return value of new by reference is deprecated in D:\xampp\htdocs\hes\system\codeigniter\Common.php on line 123
       SOLVE to replace -> $objects[$class] =& new $name(); to $objects[$class] = new $name();
    Deprecated: Assigning the return value of new by reference is deprecated in D:\xampp\htdocs\hes\system\codeigniter\Common.php on line 129
     SOLVE to replace ->  $objects[$class] =& new $name(); to $objects[$class] =new $name();

      A PHP Error was encountered

    Severity: 8192
    Message: Function set_magic_quotes_runtime() is deprecated
    Filename: codeigniter/CodeIgniter.php
    Line Number: 60

    SOLVE to replace - set_magic_quotes_runtime(0);  to ini_set("magic_quotes_runtime",0);

    then restart your web server application.,.,.

    A PHP Error was encountered

    Severity: 8192
    Message: Assigning the return value of new by reference is deprecated
    Filename: libraries/Loader.php
    Line Number: 248

    SOLVE to replace -     $CI->dbutil =& new $class();  to     $CI->dbutil = new $class();

    A PHP Error was encountered

    Severity: 8192
    Message: Assigning the return value of new by reference is deprecated
    Filename: database/DB.php
    Line Number: 112

    SOLVE to replace -    $DB =& new $driver($params);  to  $DB = new $driver($params); 
    then restart your web server application.,.,.

    powered by amazon

    count number of word from a string in php

    <?php
    $str = "extract word from a sring using php";
    //before
    $extractword= str_word_count($str);
    $extword=explode(" ",$str);
    //count word from string
    echo count($extword);
    echo "total word in a string is =$extractword<br>";
    // after
    $couter=1;
    foreach($extword as $word){
    echo "$couter  ".$word."<br>";
    $couter=$couter+1;


    }
    ?>

    how to extract number of word in a string and string count using php

    <?php
    $str = "extract word from a sring using php";
    //before
    $extractword= str_word_count($str);
    $extword=explode(" ",$str);
    //count word from string
    echo count($extword);
    echo "total word in a string is =$extractword<br>";
    // after
    $couter=1;
    foreach($extword as $word){
    echo "$couter  ".$word."<br>";
    $couter=$couter+1;


    }
    ?>provided by amazon and ebay

    Thursday, September 13, 2012

    simple example add , delete ,update ,show records in cakephp

    stp-1
    CREATE TABLE IF NOT EXISTS `movies` (
      `id` char(36) NOT NULL,
      `title` varchar(255) DEFAULT NULL,
      `genre` varchar(45) DEFAULT NULL,
      `rating` varchar(45) DEFAULT NULL,
      `format` varchar(45) DEFAULT NULL,
      `length` varchar(45) DEFAULT NULL,
      `created` datetime DEFAULT NULL,
      `modified` datetime DEFAULT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
    ----------------------------------------------------------------------------------------------------------
    stp- 2->create controller page under(moviescontroller.php)-> D:\xampp\htdocs\cakephp_lt\app\Controller\moviescontroller.php and paste below code
    ----------------------------------------------------------------------------------------------------------
    <?php
    class MoviesController extends AppController {
        public $components = array('Session');
       
       
            public function index()
            {
                $movies = $this->Movie->find('all');
                $this->set('movies', $movies);
             }
       
                public function add()
                 {
                        if (!empty($this->data)) {
                        $this->Movie->create($this->data);
                        if ($this->Movie->save()) {
                        $this->Session->setFlash('The movie has been saved');
                        $this->redirect(array('action' => 'add'));
                        } else {
                        $this->Session->setFlash
                        ('The movie could not be saved. Please, try again.');
                        }
                        }
                }
                   
               
                public function delete($id = null)
                 {
                    if (!$id) {
                    $this->Session->setFlash('Invalid id for movie');
                    $this->redirect(array('action' => 'index'));
                    }
                    if ($this->Movie->delete($id)) {
                    $this->Session->setFlash('Movie deleted');
                    } else {
                    $this->Session->setFlash(__('Movie was not deleted',
                    true));
                    }
                    $this->redirect(array('action' => 'index'));
                 }



                function edit($id = null) {
                        if (!$id && empty($this->data)) {
                            $this->Session->setFlash('Invalid movie');
                            $this->redirect(array('action' => 'index'));
                        }
                        if (!empty($this->data)) {
                            if ($this->Movie->save($this->data)) {
                                $this->Session->setFlash('The movie has been saved');
                                $this->redirect(array('action' => 'index'));
                            } else {
                                $this->Session->setFlash('The movie could not be saved. Please, try again.');
                            }
                        }
                        if (empty($this->data)) {
                            $this->data = $this->Movie->read(null, $id);
                        }
                    }
                   
        function view($id = null) {
            if (!$id) {
                $this->Session->setFlash('Invalid movie');
                $this->redirect(array('action' => 'index'));
            }
            $this->set('movie', $this->Movie->findById($id));
        }
    }
    ?>
    -------------------------------------------------------------------------------------------------------------
    create view file for show ,add,edit,delete under D:\xampp\htdocs\cakephp_lt\app\View\movies\(add.ctpedit.ctp,index.ctp,view.ctp)
    ------------------------------------------------------------------------------------------------------------

    add.ctp
    ------------------------------------
    <div class="movies form">
    <?php
    echo $this->Form->create('Movie');
    echo $this->Form->inputs(array('title', 'genre', 'rating', 'format', 'length'));
    echo $this->Form->end('Add');
    ?>
    </div>

    <div class="actions">
        <h3>Actions</h3>
        <ul>
            <li><?php echo $this->Html->link('List of bikash store', array('action' => 'index'));?></li>
        </ul>
    </div>
    ----------------------------------
    edit.ctp
    --------------------------------
    <div class="movies form">
    <?php
    echo $this->Form->create('Movie');
    echo $this->Form->inputs(array('id', 'title', 'genre', 'rating', 'format', 'length'));
    echo $this->Form->end('Edit');
    ?>
    </div>
    <div class="actions">
        <h3>Actions</h3>
        <ul>
            <li><?php echo $this->Html->link('List Movies',
    array('action' => 'index'));?></li>
        </ul>
    </div>
    ----------------------------------
    index.ctp
    --------------------------------
    <div class="movies index">
        <h2>Movies</h2>
        <table cellpadding="0" cellspacing="0">
            <tr>
                <th>Title</th>
                <th>Genre</th>
                <th>Rating</th>
                <th>Format</th>
                <th>Length</th>
                <th class="actions">Actions</th>
            </tr>
        <?php foreach ($movies as $movie): ?>
        <tr>
            <td><?php echo $movie['Movie']['title']; ?> </td>
            <td><?php echo $movie['Movie']['genre']; ?> </td>
            <td><?php echo $movie['Movie']['rating']; ?> </td>
            <td><?php echo $movie['Movie']['format']; ?> </td>
            <td><?php echo $movie['Movie']['length']; ?> </td>
            <td class="actions">
                <?php echo $this->Html->link('View',
    array('action' => 'view', $movie['Movie']['id'])); ?>
                <?php echo $this->Html->link('Edit',
    array('action' => 'edit', $movie['Movie']['id'])); ?>
                <?php echo $this->Html->link('Delete',
    array('action' => 'delete', $movie['Movie']['id']),
    null, sprintf('Are you sure you want to delete %s?', $movie['Movie']['title'])); ?>
            </td>
        </tr>
        <?php endforeach; ?>
        </table>
    </div>
    <div class="actions">
        <h3>Actions</h3>
        <ul>
            <li><?php echo $this->Html->link('New Movie', array('action' => 'add')); ?></li>
        </ul>
    </div>

    ----------------------------------
    view.ctp
    --------------------------------
    <div class="movies view">
    <h2>Movie</h2>
        <dl>
            <dt>Title</dt>
            <dd><?php echo $movie['Movie']['title']; ?></dd>
            <dt>Genre</dt>
            <dd><?php echo $movie['Movie']['genre']; ?></dd>
            <dt>Rating</dt>
            <dd><?php echo $movie['Movie']['rating']; ?></dd>
            <dt>Format</dt>
            <dd><?php echo $movie['Movie']['format']; ?></dd>
            <dt>Length</dt>
            <dd><?php echo $movie['Movie']['length']; ?></dd>
            <dt>Created</dt>
            <dd><?php echo $movie['Movie']['created']; ?></dd>
            <dt>Modified</dt>
            <dd><?php echo $movie['Movie']['modified']; ?></dd>
        </dl>
    </div>


    <div class="actions">
        <h3>Actions</h3>
        <ul>
            <li><?php echo $this->Html->link
    ('Edit Movie', array('action' => 'edit', $movie['Movie']['id'])); ?> </li>
            <li><?php echo $this->Html->link
    ('Delete Movie', array('action' => 'delete', $movie['Movie']['id']),
    null, sprintf('Are you sure you want to delete # %s?', $movie['Movie']['id'])); ?> </li>
            <li><?php echo $this->Html->link
    ('List Movies', array('action' => 'index')); ?> </li>
            <li><?php echo $this->Html->link
    ('New Movie', array('action' => 'add')); ?> </li>
        </ul>
    </div>
    ----------------------------------------------------------------------
    then you can also insert, updata and delete can do but if you want to validation your form fields then you have to create e a model to validatae
    -------------------------------------------------------------------------
    create model uder->D:\xampp\htdocs\cakephp_lt\app\Model\(movie.php)
    ------------------------------------------------------------------------------
    you can validate for your fields using model paste below these code
    ----------------------------------------------
    <?php
    class Movie extends AppModel {

       var $name = 'movie';  
        var $validate =array(
        'title' =>array(
                   'alphaNumeric' =>array(
                   'rule' => array('minLength',2),
                   'required' => true,
                   'message' => 'Enter should be minimum 2 only')              
                   ),
        'genre' =>array(
                   'alphaNumeric' =>array(
                   'rule' => array('minLength',4),
                   'required' => true,
                   'message' => 'Enter should be minimum 4 only')              
                   ),
       
               
        'rating' =>array(
                   'alphaNumeric' =>array(
                   'rule' => array('minLength',2),
                   'required' => true,
                   'message' => 'Enter should be minimum 4 only')              
                   )
       
                );
      
    }
    ?>

    i hope every one can easily understand please:)

    Tuesday, September 11, 2012

    facebook login using php and get user emai id and orther data from face book





    stp-1->include_once(COMMONINCLUDES.'classes/facebook.php');
    --------------------------------------------------------------------------
    stp-2
    ------------------------------------------------------------------------
    class facebookapi {
       
       
        function facebookapi($postArr)
        {       
            global $g_criteria1;
           
            parent :: CommonClass();
            //parent :: Facebook();

           
                   
            $this->CheckGetMagicQuotes($postArr);
           
            switch($g_criteria1)
            {
               
                case "nu":
                    $this->News_Update();
                break;
               
                case "tm":
                    $this->Testimonial();
                                   
               
                case "fcall":
                    $this->Facebook_Site_Callback();
               
               
                case "flogin":
                    $this->Facebook_Login();
                   
                case "fus":
                    $this->Facebook_Save_User();
                   
                   
                default:
                    $this->Facebook_Login();
            }
        }
       
       
        /*==============================================
            Author     :     bikash rajan nayak
            Modified By :  bikash rajan nayak
            Date    :    Nov 03, 2011
            Function to display home page
        ===================================================*/   
       
       
       
        function News_Update()
        {
       
            $smarty = new Smarty;
            $smarty->compile_check = true;
            $smarty->debugging = false;   
           
            $trail = new Trail();
            $trail->addStep('News & Update');
            $smarty->assign('TPL_PAGE_TITLE', 'News & Update');
           
            $plan_list_Order = $this->GetHomePlanList_Order_Two();
            $smarty->assign('TPL_PLAN_LIST_ORDERBY', $plan_list_Order);
           
            $news_list = $this->GetNEWS_List('I');
           
            $smarty->assign('TPL_NEWS_LIST', $news_list);
                   
            $smarty->assign_by_ref('trail', $trail->path);
            $smarty->display('news-and-update.tpl');
        }
       
        function Facebook_Site_Callback()
        {
       
            $smarty = new Smarty;
            $smarty->compile_check = true;
            $smarty->debugging = false;   
                   
            $hidArr = array();
            $hidArr = $this->GetHiddenVarVal($this);       
                                       
                       
                       
                       
                                    $facebook = new Facebook(array('appId'  => '17378553343966053114','secret' => '63bb9447a4cf7df7d4be985bs55a6df3b648a9d',));
                                    // Get User ID
                                    $user = $facebook->getUser();
                                   
                                    if ($user)
                                    {
                                    try
                                    {
                                   
                                    // Proceed knowing you have a logged in user who's authenticated.
                                        $user_profile = $facebook->api('/me');
                                       
                                       
                                            $Fuid = $user_profile['id'];
                                            $smarty->assign('FACE_UID',$Fuid);
                                           
                                            $FemailID = $user_profile['email'];
                                            $smarty->assign('FACE_EMAILID',$FemailID);
                                           
                                            $FfirstName = $user_profile['first_name'];
                                            $smarty->assign('FACE_FirstName',$FfirstName);
                                           
                                            $FlastName = $user_profile['last_name'];
                                            $smarty->assign('FACE_LastName',$FlastName);
                                           
                                            if(isset($user_profile['gender']))
                                            {
                                                $Fgender = $user_profile['gender'];
                                                $smarty->assign('FACE_gender',$Fgender);
                                            }
                                           
                                        //echo '<pre>'; print_r($user_profile); exit;
                                                                           
                                        //session_destroy();
                                                                           
                                            $u_selquery = "SELECT
                                                                        fld_id
                                                                FROM
                                                                                tbl_user
                                                                WHERE 
                                                                        fld_email = '$FemailID' AND flogin ='$Fuid' ";            
                                               
                                       
                                        $u_queryexe = mysql_query($u_selquery);
                                        if(mysql_affected_rows() > 0)
                                        {
                                           
                                                                                   
                                            $whrCls1 = " WHERE (fld_email='$FemailID') AND flogin ='$Fuid' ";
                                            $table_fields1 = array('fld_id', 'fld_userName',  'fld_firstName', 'fld_lastName', 'fld_status', 'flogin');
                                            $sql_sel1 = $this->buildSelectSQL('tbl_user', $table_fields1, $whrCls1);
                                            $rs_valid1 = @mysql_query($sql_sel1);
                                           
                                                if($rs_valid1 && @mysql_num_rows($rs_valid1) > 0)
                                                    {
                                                   
                                                        $row = @mysql_fetch_assoc($rs_valid1);
                                                        $user_name = $row['fld_userName'];
                                                        $id = $row['fld_id'];
                                                        $fullName = $row['fld_firstName'];
                                                        $email = $FemailID;
                                                       
                                                        $facebookId = $row['flogin'];
                                                       
                                                        $objSessions = new Sessions($user_name, $id, 'customer', $fullName, $facebookId , '', $email);
                                                        $objSessions->set_sessions();
                                                       
                                                        //$_SESSION['facebookId'] = $facebookId;
                                                       
                                                       
                                                        //echo "<pre>";print_r($_SESSION);
                                                        //exit;

                                                     
    //$logoutUrl = $facebook->getLogoutUrl();
    //header("Location: $logoutUrl");
                                                        $this->redirectPage('myaccount.php?event=myaccount', $hidArr);   
                                                        exit;
                                                                   
                                                                   
                                                    }
                                                    else
                                                    {
                                                        $hidArr = 'user name alrady exist, please choose another user name';
                                                        $this->redirectPage('myaccount.php?event=myaccount', $hidArr);   
                                                        exit;
                                                   
                                                    }
                       
                                       
                                        }
                                        else
                                        {
                                       
                                       
                                        //$logoutUrl = $facebook->getLogoutUrl();
                                        //header("Location: $logoutUrl");

                                        //$smarty->display('facebook-login.tpl');
                                        //exit;
                                        //07-March-Work............................................................................
                                       
                                       
                                            $Fuid = $user_profile['id'];
                                            $smarty->assign('FACE_UID',$Fuid);
                                           
                                            $FemailID = $user_profile['email'];
                                            $smarty->assign('FACE_EMAILID',$FemailID);
                                           
                                            $FfirstName = $user_profile['first_name'];
                                            $smarty->assign('FACE_FirstName',$FfirstName);
                                           
                                            $FlastName = $user_profile['last_name'];
                                            $smarty->assign('FACE_LastName',$FlastName);
                                           
                                            if(isset($user_profile['gender']))
                                            {
                                                $Fgender = $user_profile['gender'];
                                                $smarty->assign('FACE_gender',$Fgender);
                                            }
                                       
    //echo "hello1";
    //exit;   

                                        if($Fuid != '' && $FemailID != '' && $FfirstName != '' && $FlastName != '' )
                                        {
                                       
                                                $defaultImage = '2011_1.gif';
                                               
                                                $tbl_fld = array(
                                                'fld_userName', 'fld_email', 'fld_firstName', 'fld_lastName',
                                                'fld_sex', 'fld_image', 'fld_profileView','fld_wishView',
                                                'fld_status' ,'fld_creationDate','flogin' 
                                                );
                                                $tbl_fld_val = array(   
                                                $FemailID, $FemailID,  $FfirstName, $FlastName,
                                                $Fgender, $defaultImage, '1' , '1',
                                                '1', date('Y-m-d H:i:s'), $Fuid    
                                                );
                                               
                                                $sql_ins = $this->buildManipSQL('tbl_user', $tbl_fld, $tbl_fld_val, 'IN');
                                                $rs = mysql_query($sql_ins);
                                                $fld_id = mysql_insert_id();
                                               
                                               
                                                if($rs &&  $fld_id!='')
                                                {   
                                                        $whrCls1 = " WHERE (fld_userName ='".$FemailID."' OR fld_email='".$FemailID."') AND flogin='$Fuid'";
                                                        $table_fields1 = array('fld_id', 'fld_firstName', 'fld_lastName', 'fld_status');
                                                        $sql_sel1 = $this->buildSelectSQL('tbl_user', $table_fields1, $whrCls1);
                                                        $rs_valid1 = @mysql_query($sql_sel1);
                                                       
                                                        if($rs_valid1 && @mysql_num_rows($rs_valid1) > 0)
                                                            {
                                                               
                                                                $row = @mysql_fetch_assoc($rs_valid1);
                                                                $user_id = $row['fld_id'];
                                                               
                                                                if($row['fld_status'] == 0)
                                                                {                   
                                                                    $hidArr['ec'] = NOT_ACT;                   
                                                                    $hidArr['am'] = "YES";
                                                                    $this->redirectPage('login.php', $hidArr);
                                                                    exit;
                                                                }
                                                                else
                                                                {
                                                               
                                                                    $user_name = $FemailID;
                                                                    $id = $row['fld_id'];
                                                                    $fullName = $row['fld_firstName'];
                                                                    $email = $FemailID;
                                                                    $objSessions = new Sessions($user_name, $id, 'customer', $fullName, '', '', $email);
                                                                    $objSessions->set_sessions();
                                                                    //echo "<pre>";print_r($_SESSION);
                                                                    $this->redirectPage('myaccount.php?event=myaccount', $hidArr);   
                                                                    exit;                   
                                                                }               
                                                            }
                                                       
                                               
                                                }
                                   
                                       
                                        }
                                       
                                       
                                       
                                       
                                       
                                       
                                       
                                       
                                       
                                       
                                       
                                       
                                       
                                       
                                       
                                       
                                       
                                       
                                        }
                                   
                                    }
                                    catch (FacebookApiException $e)
                                    {
                                    error_log($e);
                                    $user = null;
                                    }
                                    }
                                   
                                   
                                   
                                    // Login or logout url will be needed depending on current user state.
                                    if ($user) {
                                   
                                   
                                    $logoutUrl = $facebook->getLogoutUrl();
                                   
                                    } else
                                    {
                                        $loginUrl = $facebook->getLoginUrl(array('scope' => 'email,read_stream'));
                                        //echo '<script>self.location = '.$loginUrl.';
                                        header("Location: $loginUrl");
                                            //$hidArr['ec'] = " ";
                                            //$this->redirectPage($loginUrl, $hidArr);
                                    }
                                   
           
                   
           
           
        }
       
       
       
       
       
       
       
       
       

        function Facebook_Login()
        {
            $smarty = new Smarty;
            $smarty->compile_check = true;
            $smarty->debugging = false;   
           
           
           
           
           
           
           
            $facebook = new Facebook(array('appId'  => '1737324242385966053114','secret' => '63bb9447a4cf7df7d4be985b3s6s53a2db648a9d',));

            // Get User ID
            echo "hjjdfgljf";
            $user = $facebook->getUser();
            if ($user) {
              try {
                // Proceed knowing you have a logged in user who's authenticated.
                $user_profile = $facebook->api('/me');
              } catch (FacebookApiException $e) {
                error_log($e);
                $user = null;
              }
            }
        //echo '<pre>'; print_r($user_profile); exit;
           
            $Fuid = $user_profile['id'];
            $smarty->assign('FACE_UID',$Fuid);
           
            $FemailID = $user_profile['email'];
            $smarty->assign('FACE_EMAILID',$FemailID);
           
            $FfirstName = $user_profile['first_name'];
            $smarty->assign('FACE_FirstName',$FfirstName);
           
            $FlastName = $user_profile['last_name'];
            $smarty->assign('FACE_LastName',$FlastName);
           
            $Fgender = $user_profile['gender'];
            $smarty->assign('FACE_gender',$Fgender);
           
            //echo '<pre>'; print_r( $user_profile); exit;
            //echo "<pre>"; print_r($_SESSION); exit;   
            //echo $facebook->getLogoutUrl();
           
           
            $cmsPageContent = $this->GetHomeCMSPage(1);
            $pageUrl = $this->getPageURLString();
            $smarty->assign('MENU_SEL',$pageUrl);
           
            //echo $cmsPageTitle = $cmsPageContent[0]['id'];
            $cmsPageTitle = $cmsPageContent[0]['title'];
            $cmsPageContent = $cmsPageContent[0]['content'];
           
            $smarty->assign('TPL_CMS_PAGE_TITLE', $cmsPageTitle);
            $smarty->assign('TPL_CMS_PAGE_CONTENT', $cmsPageContent);
                   
           
           
           
            //echo "<pre>"; print_r($cmsPageContent); exit;
            //$smarty->assign('TPL_PLAN_LIST_ORDERBY', $plan_list_Order);
           
           
            $eventSlider = $this->GetUserEventSlider();
            $smarty->assign('event_list', $eventSlider);   
            //echo "<pre>";    print_r($eventSlider);exit;
                   
            $smarty->display('facebook-login.tpl');
           
           
           
        }
       
       
       
        function Facebook_Save_User()
        {
       
            $smarty = new Smarty;
            $smarty->compile_check = true;
            $smarty->debugging = false;
           
            $hidArr = array();
            //$hidArr = $this->GetHiddenVarVal($this);
           
            $status = '0';       
            $ipaddress=$_SERVER['REMOTE_ADDR'];   
           
                   
            //echo "<br />";
             date('Y-m-d H:i:s');
            //exit;
            $defaultImage = '2011_1.gif';
                   
             if($this->hidface_gender == 'male')
             {
                 $sex = '1';
             }
             else
             {
                 $sex = '0';
             }
           
           
             if($this->txtemailID != '')
            {
                $u_selquery = "SELECT
                                    fld_id
                             FROM
                                     tbl_user
                            WHERE 
                                    fld_userName = '$this->txtUserName' OR  fld_email = '$this->txtemailID' ";            
           
             $u_queryexe = mysql_query($u_selquery);
             if(mysql_affected_rows() > 0)
                 {
                    $hidArr['ec'] = 'User Name or Email ID already exit Plz choose another name';
                    $this->redirectPage('sign-up.php?event=ur', $hidArr);
                }
             }   
           
                   
           
           
             if($this->hidface_emailid != '' && $this->hidface_fname != '' && $this->hidface_lname != '' && $this->hidface_gender != '' && $this->txtUserName != ''
                && $this->txtPassword != ''
                )
            {
             
           
                $defaultImage = '2011_1.gif';
                $tbl_fld = array(
                                    'fld_userName', 'fld_email', 'fld_password', 'fld_firstName', 'fld_lastName',
                                    'fld_sex', 'fld_image', 'fld_profileView','fld_wishView','fld_ipAddr',
                                    'fld_status' ,'fld_creationDate','flogin' 
                                );
                $tbl_fld_val = array(   
                                        $this->txtUserName, $this->hidface_emailid,  md5($this->txtPassword), $this->hidface_fname, $this->hidface_lname,
                                        $sex, $defaultImage, '1' , '1',  $ipaddress,
                                        '1', date('Y-m-d H:i:s'), $this->hidface_id    
                                    );
               
                $sql_ins = $this->buildManipSQL('tbl_user', $tbl_fld, $tbl_fld_val, 'IN');
                $rs = mysql_query($sql_ins);
                $fld_id = mysql_insert_id();
                                   
                if($rs)
                {   
               
                     $txt_pass = md5($this->txtPassword);
                if($this->txtUserName != '' && $fld_id != '')
                {
               
                           
                   $whrCls1 = " WHERE (fld_userName ='".$this->txtUserName."' OR fld_email='".$this->hidface_emailid."') AND fld_password='$txt_pass'";
                   $table_fields1 = array('fld_id', 'fld_firstName', 'fld_lastName', 'fld_status');
                     $sql_sel1 = $this->buildSelectSQL('tbl_user', $table_fields1, $whrCls1);
           
               
                $rs_valid1 = @mysql_query($sql_sel1);
                if($rs_valid1 && @mysql_num_rows($rs_valid1) > 0)
                {
                   
                    $row = @mysql_fetch_assoc($rs_valid1);
                    $user_id = $row['fld_id'];
                   
                    if($row['fld_status'] == 0)
                    {                   
                        $hidArr['ec'] = NOT_ACT;                   
                        $hidArr['am'] = "YES";
                        $this->redirectPage('login.php', $hidArr);
                        exit;
                    }
                    else
                    {
                   
                        $user_name = $this->txtUserName;
                        $id = $row['fld_id'];
                        $fullName = $row['fld_firstName'];
                        $email = $this->txtUserName;
                        $objSessions = new Sessions($user_name, $id, 'customer', $fullName, '', '', $email);
                        $objSessions->set_sessions();
                        echo "<pre>";print_r($_SESSION);
                        $this->redirectPage('myaccount.php?event=myaccount', $hidArr);   
                        exit;                   
                    }               
                }
               
            }   
                }
                else
                {
                    $hidArr['ec'] = USER_ADD_FAIL;
                    $this->redirectPage('sign-up.php?event=ur', $hidArr);
                }
                 }
            else
            {

                $hidArr['ec'] = MEND_FIELDS;
                $this->redirectPage('sign-up.php?event=ur', $hidArr);
                exit;
            }
           
        }

     }
    ---------------------end face book class--------------------------------------------

    last step pass user request for login
    include_once('classes/facebookapi.class.php');

    $obj_Facebookapi = new facebookapi($_REQUEST);