phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] old/wcm/inc/class.sosite.inc.php, 1.1


From: nomail
Subject: [Phpgroupware-cvs] old/wcm/inc/class.sosite.inc.php, 1.1
Date: Thu, 30 Dec 2004 09:13:57 +0100

Update of /old/wcm/inc
Added Files:
        Branch: 
          class.sosite.inc.php

date: 2004/12/30 08:13:57;  author: skwashd;  state: Exp;

Log Message:
keep historic record for wcm
=====================================================================
<?php
  /**************************************************************************\
  * phpGroupWare - WCM                                                       *
  * http://www.phpgroupware.org                                              *
  * Written by Miles Lott <address@hidden>                         *
  * --------------------------------------------                             *
  *  This program is free software; you can redistribute it and/or modify it *
  *  under the terms of the GNU General Public License as published by the   *
  *  Free Software Foundation; either version 2 of the License, or (at your  *
  *  option) any later version.                                              *
  \**************************************************************************/

  /* $Id: class.sosite.inc.php,v 1.1 2004/12/30 08:13:57 skwashd Exp $ */

        class sosite
        {
                var $debug  = False;
                var $siteid = '';
                var $site   = array();
                var $table  = 'phpgw_wcm_sites';

                function sosite()
                {
                }

                function list_sites($data='',&$total)
                {
                        if(is_array($data))
                        {
                                if($this->debug) { _debug_array($data); }
                                list($start,$sort,$order,$query,$limit) = $data;
                        }
                        return 
$this->get_list($start,$sort,$order,$query,$limit,$total);
                }

                function read($id,$full=False)
                {
                        return $this->read_repository($id,$full);
                }

                function add($site_info)
                {
                        return $this->create($site_info);
                }

                function update($site_info)
                {
                        $this->site = $site_info;
                        $this->save_repository($site_info['site_id']);
                        return $this->read_repository($site_info['site_id']);
                }

                function delete($id)
                {
                        return $this->delete($id);
                }

                function read_repository($siteid='',$full=False)
                {
                        $this->site = array();

                        if(!$siteid)
                        {
                                $siteid = $this->siteid;
                        }
                        $sql = "SELECT * FROM $this->table WHERE site_id=" . 
intval($siteid);
                        $GLOBALS['phpgw']->db->query($sql,__LINE__,__FILE__);
                        if($GLOBALS['phpgw']->db->next_record())
                        {
                                $this->site['site_id']       = 
$GLOBALS['phpgw']->db->f('site_id');
                                $this->site['site_name']     = 
stripslashes($GLOBALS['phpgw']->db->f('site_name'));
                                $this->site['site_title']    = 
stripslashes($GLOBALS['phpgw']->db->f('site_title'));
                                $this->site['site_url']      = 
$GLOBALS['phpgw']->db->f('site_url');
                                $this->site['site_root']     = 
$GLOBALS['phpgw']->db->f('site_root');
                                $this->site['site_security'] = 
$GLOBALS['phpgw']->db->f('site_security');
                                $this->site['username']      = 
stripslashes($GLOBALS['phpgw']->db->f('username'));
                                $this->site['password']      = 
stripslashes($GLOBALS['phpgw']->db->f('password'));
                                $this->site['admin_name']    = 
stripslashes($GLOBALS['phpgw']->db->f('admin_name'));
                                $this->site['admin_email']   = 
stripslashes($GLOBALS['phpgw']->db->f('admin_email'));
                                $tmp = 
unserialize($GLOBALS['phpgw']->db->f('site_pages'));
                                $this->site['site_pages']    = is_array($tmp) ? 
$tmp : array();
                                $this->site['site_header']   = 
$GLOBALS['phpgw']->db->f('site_header');
                                $this->site['site_footer']   = 
$GLOBALS['phpgw']->db->f('site_footer');
                                $this->site['site_version']  = 
$GLOBALS['phpgw']->db->f('site_version');
                                $this->site['site_left']     = 
$GLOBALS['phpgw']->db->f('site_left');
                                $this->site['site_mid']      = 
$GLOBALS['phpgw']->db->f('site_mid');
                                $this->site['site_right']    = 
$GLOBALS['phpgw']->db->f('site_right');
                                $this->site['site_paneo']    = 
$GLOBALS['phpgw']->db->f('site_paneo');
                                $this->site['site_pubtype']  = 
$GLOBALS['phpgw']->db->f('site_pubtype');
                                $this->site['site_puburl']   = 
$GLOBALS['phpgw']->db->f('site_puburl');
                                $this->site['site_pubport']  = 
$GLOBALS['phpgw']->db->f('site_pubport');
                                $this->site['site_bgcolor']  = 
$GLOBALS['phpgw']->db->f('site_bgcolor');
                        }
                        if($full)
                        {
                                $pages = CreateObject('wcm.sopage');
                                @reset($this->site['site_pages']);
                                //_debug_array($this->site['site_pages']);
                                $new = array();
                                while(list($key,$value) = 
@each($this->site['site_pages']))
                                {
                                        $new[$key] = 
$pages->read_repository($value,True);
                                }
                                $this->site['site_pages'] = $new;
                        }
                        //_debug_array($this->site);
                        return $this->site;
                }

                function save_repository($siteid='')
                {
                        if(!$siteid)
                        {
                                $siteid = $this->siteid;
                        }
                        if($siteid && is_array($this->site))
                        {
                                $tmp = is_array($this->site['site_pages']) ? 
serialize($this->site['site_pages']) : serialize(array('none'));

                                $sql = "UPDATE $this->table SET "
                                        . "site_name='"     . 
$GLOBALS['phpgw']->db->db_addslashes($this->site['site_name']) . "',"
                                        . "site_title='"    . 
$GLOBALS['phpgw']->db->db_addslashes($this->site['site_title']) . "',"
                                        . "site_root='"     . 
$this->site['site_root'] . "',"
                                        . "site_url='"      . 
$this->site['site_url']  . "',"
                                        . "site_security='" . 
$this->site['site_security']  . "',"
                                        . "username='"      . 
$GLOBALS['phpgw']->db->db_addslashes($this->site['username'])  . "',"
                                        . "password='"      . 
$GLOBALS['phpgw']->db->db_addslashes($this->site['password'])  . "',"
                                        . "admin_name='"    . 
$GLOBALS['phpgw']->db->db_addslashes($this->site['admin_name'])  . "',"
                                        . "admin_email='"   . 
$GLOBALS['phpgw']->db->db_addslashes($this->site['admin_email']) . "',"
                                        . "site_pages='"    . $tmp . "',"
                                        . "site_header='"   . 
$this->site['site_header'] . "',"
                                        . "site_footer='"   . 
$this->site['site_footer'] . "',"
                                        . "site_left="      . 
intval($this->site['site_left']) . ","
                                        . "site_mid="       . 
intval($this->site['site_mid']) . ","
                                        . "site_right="     . 
intval($this->site['site_right']) . ","
                                        . "site_version='"  . 
$this->site['site_version'] . "',"
                                        . "site_paneo="     . 
intval($this->site['site_paneo']) . ","
                                        . "site_pubtype='"  . 
$this->site['site_pubtype'] . "',"
                                        . "site_puburl='"   . 
$this->site['site_puburl']  . "',"
                                        . "site_pubport="   . 
intval($this->site['site_pubport']) . ","
                                        . "site_bgcolor='"  . 
$this->site['site_bgcolor'] . "'"
                                        . " WHERE site_id=" . intval($siteid);
                                
$GLOBALS['phpgw']->db->query($sql,__LINE__,__FILE__);
                                return True;
                        }
                        return False;
                }

                function create($site_info='')
                {
                        if(!is_array($site_info))
                        {
                                return False;
                        }
                        $tmp = is_array($site_info['site_pages']) ? 
serialize($site_info['site_pages']) : serialize(array('none'));
                        $sql = "INSERT INTO $this->table 
(site_name,site_title,site_root,site_url,site_security,"
                                . 
"username,password,admin_name,admin_email,site_left,site_mid,site_right,"
                                . 
"site_pages,site_header,site_footer,site_version,site_paneo,"
                                . 
"site_pubtype,site_puburl,site_pubport,site_bgcolor) VALUES('"
                                . 
$GLOBALS['phpgw']->db->db_addslashes($site_info['site_name']) . "','"
                                . 
$GLOBALS['phpgw']->db->db_addslashes($site_info['site_title']) . "','"
                                . $site_info['site_root'] . "','"
                                . $site_info['site_url'] . "','" . 
$site_info['site_security'] . "','"
                                . 
$GLOBALS['phpgw']->db->db_addslashes($site_info['username']) . "','"
                                . 
$GLOBALS['phpgw']->db->db_addslashes($site_info['password']) . "','"
                                . 
$GLOBALS['phpgw']->db->db_addslashes($site_info['admin_name']) . "','"
                                . 
$GLOBALS['phpgw']->db->db_addslashes($site_info['admin_email']) . "',"
                                . intval($site_info['site_left'])  . ","
                                . intval($site_info['site_mid'])   . ","
                                . intval($site_info['site_right']) . ",'"
                                . $tmp . "','"
                                . $site_info['site_header'] . "','"
                                . $site_info['site_footer'] . "','" . 
$site_info['site_version'] . "',"
                                . intval($site_info['site_paneo']) . ",'"
                                . $site_info['site_pubtype'] . "','"
                                . $site_info['site_puburl'] . "',"
                                . intval($site_info['site_pubport']) . ",'"
                                . $site_info['site_bgcolor'] . "')";
                        $GLOBALS['phpgw']->db->query($sql,__LINE__,__FILE__);

                        $sql = "SELECT site_id FROM $this->table WHERE 
site_name='" . $site_info['site_name'] . "'";
                        $GLOBALS['phpgw']->db->query($sql,__LINE__,__FILE__);
                        if($GLOBALS['phpgw']->db->next_record())
                        {
                                $site_info['site_id'] = 
$GLOBALS['phpgw']->db->f(0);
                                $this->siteid = $site_info['site_id'];
                                $this->site   = $site_info;
                                return $this->siteid;
                        }
                        return False;
                }

                function delete($siteid='')
                {
                        if(!$siteid)
                        {
                                $siteid = $this->siteid;
                        }
                        if($siteid)
                        {
                                $sql = "DELETE FROM $this->table WHERE 
site_id=$siteid";
                                
$GLOBALS['phpgw']->db->query($sql,__LINE__,__FILE__);
                                return True;
                        }
                        return False;
                }

                function 
get_list($start='',$sort='',$order='',$query='',$limit='',&$total)
                {
                        $this->sites = array();

                        if (!$sort)
                        {
                                $sort = 'DESC';
                        }
                        if ($query)
                        {
                                $whereclause = "WHERE site_name LIKE '%$query%'"
                                        . "OR site_title  LIKE '%$query%'"
                                        . "OR site_url  LIKE '%$query%'"
                                        . "OR admin_name  LIKE '%$query%'"
                                        . "OR admin_email LIKE '%$query%'";
                        }
                        if ($order)
                        {
                                $orderclause = 'ORDER BY ' . $order . ' ' . 
$sort;
                        }
                        else
                        {
                                $orderclause = 'ORDER BY site_name ASC';
                        }

                        $sql = "SELECT * FROM $this->table $whereclause 
$orderclause";
                        $GLOBALS['phpgw']->db->query($sql,__LINE__,__FILE__);
                        
                        while ($GLOBALS['phpgw']->db->next_record())
                        {
                                
$this->sites[$GLOBALS['phpgw']->db->f('site_name')]['site_id']       = 
$GLOBALS['phpgw']->db->f('site_id');
                                
$this->sites[$GLOBALS['phpgw']->db->f('site_name')]['site_name']     = 
stripslashes($GLOBALS['phpgw']->db->f('site_name'));
                                
$this->sites[$GLOBALS['phpgw']->db->f('site_name')]['site_title']    = 
stripslashes($GLOBALS['phpgw']->db->f('site_title'));
                                
$this->sites[$GLOBALS['phpgw']->db->f('site_name')]['site_url']      = 
$GLOBALS['phpgw']->db->f('site_url');
                                
$this->sites[$GLOBALS['phpgw']->db->f('site_name')]['site_root']     = 
$GLOBALS['phpgw']->db->f('site_root');
                                
$this->sites[$GLOBALS['phpgw']->db->f('site_name')]['site_security'] = 
$GLOBALS['phpgw']->db->f('site_security');
                                
$this->sites[$GLOBALS['phpgw']->db->f('site_name')]['admin_name']    = 
stripslashes($GLOBALS['phpgw']->db->f('admin_name'));
                                
$this->sites[$GLOBALS['phpgw']->db->f('site_name')]['admin_email']   = 
stripslashes($GLOBALS['phpgw']->db->f('admin_email'));
                                
$this->sites[$GLOBALS['phpgw']->db->f('site_name')]['site_header']   = 
$GLOBALS['phpgw']->db->f('site_header');
                                
$this->sites[$GLOBALS['phpgw']->db->f('site_name')]['site_footer']   = 
$GLOBALS['phpgw']->db->f('site_footer');
                                
$this->sites[$GLOBALS['phpgw']->db->f('site_name')]['site_version']  = 
$GLOBALS['phpgw']->db->f('site_version');
                                
$this->sites[$GLOBALS['phpgw']->db->f('site_name')]['site_left']     = 
$GLOBALS['phpgw']->db->f('site_left');
                                
$this->sites[$GLOBALS['phpgw']->db->f('site_name')]['site_mid']      = 
$GLOBALS['phpgw']->db->f('site_mid');
                                
$this->sites[$GLOBALS['phpgw']->db->f('site_name')]['site_right']    = 
$GLOBALS['phpgw']->db->f('site_right');
                        }
                        $this->total = $GLOBALS['phpgw']->db->num_rows();
                        $total = $this->total;
                        return $this->sites;
                }

                function formatted_list($site_id=0,$java=False,$local=False)
                {
                        if ($java)
                        {
                                $jselect = ' onChange="this.form.submit();"';
                        }
                        $select  = "\n" .'<select name="site_id"' . $jselect . 
">\n";
                        $select .= '<option value="0"';
                        if(!$site_id)
                        {
                                $select .= ' selected';
                        }
                        $selectlang = $local ? lang('Local') : lang('Please 
Select');
                        $select .= '>' . $selectlang . '</option>'."\n";

                        $x = '';
                        $slist = $this->get_list('','','','','',$x);
                        while (list($key,$val) = each($slist))
                        {
                                $foundsites = True;
                                $select .= '<option value="' . $val['site_id'] 
. '"';
                                if ($val['site_id'] == $site_id)
                                {
                                        $select .= ' selected';
                                }
                                $select .= '>' . $val['site_name'] . 
'</option>'."\n";
                        }

                        $select .= '</select>'."\n";
                        $select .= '<noscript><input type="submit" 
name="site_id_select" value="' . lang('Select') . '"></noscript>' . "\n";
                        if(!$foundsites)
                        {
                                $select = '';
                        }

                        return $select;
                }

                function name2id($site_name='')
                {
                        if(!$site_name)
                        {
                                $site_name = $this->site['site_name'];
                        }
                        if($site_name)
                        {
                                $sql = "SELECT site_id FROM $this->table WHERE 
site_name='$site_name'";
                                
$GLOBALS['phpgw']->db->query($sql,__LINE__,__FILE__);
                                if($GLOBALS['phpgw']->db->next_record())
                                {
                                        $siteid = $GLOBALS['phpgw']->db->f(0);
                                        return $siteid;
                                }
                        }
                        return False;
                }

                function id2name($siteid='')
                {
                        if(!$siteid)
                        {
                                $siteid = $this->siteid;
                        }
                        if($siteid)
                        {
                                $sql = "SELECT site_name FROM $this->table 
WHERE site_id=$siteid";
                                
$GLOBALS['phpgw']->db->query($sql,__LINE__,__FILE__);
                                if($GLOBALS['phpgw']->db->next_record())
                                {
                                        $site_name = 
$GLOBALS['phpgw']->db->f(0);
                                        return $site_name;
                                }
                        }
                        return False;
                }

                function exists($sitedata='')
                {
                        if(!$sitedata)
                        {
                                return False;
                        }
                        if(is_int($sitedata))
                        {
                                $siteid = $sitedata;
                                settype($site_name,'string');
                                $site_name = $this->id2name($siteid);
                        }
                        else
                        {
                                $site_name = $sitedata;
                        }
                        $sql = "SELECT site_id FROM $this->table WHERE 
site_name='$site_name'";
                        $GLOBALS['phpgw']->db->query($sql,__LINE__,__FILE__);
                        if($GLOBALS['phpgw']->db->next_record())
                        {
                                return True;
                        }
                        return False;
                }
        }
?>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]