使用inettuts達到個人化with PHP

  • 2270
  • 0
  • PHP
  • 2013-07-12

摘要:使用inettuts達到個人化with PHP

 

此文專貼自國外 http://jsabino.wordpress.com/2009/09/19/how-to-mimic-the-igoogle-interface-with-database/

 

 

副檔: iNettutsDB (2).zip

---------------------------------------------------------------------------------

iNettuts_rpc.php


 Should come from a session variable
$user_id="gjohn doe111";

// DB connect parameters
$server="localhost";
$user="帳號";
$password="密碼";
$database="資料庫名稱";

$table="iNettuts";
$field="config";

// DB connect
mysql_connect($server,$user,$password);
@mysql_select_db($database);


if (isset($_REQUEST["value"])) { 
  // SET value  
  
  $value=$_REQUEST["value"];
  
  $rs=mysql_query("SELECT * FROM $table WHERE user_id='$user_id'");
  if (mysql_numrows($rs)==0) 
    mysql_query("INSERT INTO $table($field,user_id) VALUES('$value','$user_id')");
  else
    mysql_query("UPDATE $table SET $field='$value' WHERE user_id='$user_id'");
  echo "OK";

} else {
  // GET value 
  
  $rs=mysql_query("SELECT $field FROM $table WHERE user_id='$user_id'");
  if ($row=mysql_fetch_row($rs)) 
    echo $row[0];
  else
    echo "";
}

mysql_close();
?>

-------------------------------------------------------------------------------------------

inettuts.js


/*
 * Script from NETTUTS.com [by Mario Jimenez] V.2 (ENHANCED, WITH DATABASE!!!)
 * @requires jQuery($), jQuery UI & sortable/draggable UI modules & jQuery COOKIE plugin
 */

var iNettuts = {
    
    jQuery : $,
    
    settings : {
        columns : '.column',
        widgetSelector: '.widget',
        handleSelector: '.widget-head',
        contentSelector: '.widget-content',
        
        /* If you don't want preferences to be saved change this value to
            false, otherwise change it to the name of the cookie: */
        saveToCookie: 'inettuts-widget-preferences',
        
        widgetDefault : {
            movable: true,
            removable: true,
            collapsible: true,
            editable: true,
            colorClasses : ['color-yellow', 'color-red', 'color-blue', 'color-white', 'color-orange', 'color-green']
        },
        widgetIndividual : {}
    },

    init : function () {
        this.attachStylesheet('inettuts.js.css');
        this.sortWidgets();
        //this.addWidgetControls();
        //this.makeSortable();
    },
    
    getWidgetSettings : function (id) {
        var $ = this.jQuery,
            settings = this.settings;
        return (id&&settings.widgetIndividual[id]) ? $.extend({},settings.widgetDefault,settings.widgetIndividual[id]) : settings.widgetDefault;
    },
    
    addWidgetControls : function () {
        var iNettuts = this,
            $ = this.jQuery,
            settings = this.settings;
            
        $(settings.widgetSelector, $(settings.columns)).each(function () {
            var thisWidgetSettings = iNettuts.getWidgetSettings(this.id);
            if (thisWidgetSettings.removable) {
                $('CLOSE').mousedown(function (e) {
                    /* STOP event bubbling */
                    e.stopPropagation();    
                }).click(function () {
                    if(confirm('This widget will be removed, ok?')) {
                        $(this).parents(settings.widgetSelector).animate({
                            opacity: 0    
                        },function () {
                            $(this).wrap('

').parent().slideUp(function () {
                                $(this).remove();
                            });
                        });
                    }
                    return false;
                }).appendTo($(settings.handleSelector, this));
            }
            
            if (thisWidgetSettings.editable) {
                $('EDIT').mousedown(function (e) {
                    /* STOP event bubbling */
                    e.stopPropagation();    
                }).toggle(function () {
                    $(this).css({backgroundPosition: '-66px 0', width: '55px'})
                        .parents(settings.widgetSelector)
                            .find('.edit-box').show().find('input').focus();
                    return false;
                },function () {
                    $(this).css({backgroundPosition: '', width: '24px'})
                        .parents(settings.widgetSelector)
                            .find('.edit-box').hide();
                    return false;
                }).appendTo($(settings.handleSelector,this));
                $('