shipy013 0 Newbie Poster

Hello everyone.
Will present you with a script that can change the templates on your site.
Script is enough to insert into your admin panel and make mjskl database.

In the theme folder there are threads that are arranged in folders in this case, there are three folders (three theme):
1.red
2.blue
3.sib_default

so if you ever want to use this simple script you only add a new folder and name it in his store everything you need for a template (css, images).

The lib folder contains two scripts one database.php settings.php and the other containing the function.

Functions are not professional but it can help first-aid.
The most important thing is to do it.

Had to go:

1. Create a new folder and set name lib and isert this script. database.php, settings.php and global

database.php

define ( 'HOST',    'localhost' );
define ( 'USER',    '' );
define ( 'PASSWORD','' );
define ( 'DB_NAME', '' );


  function sib_dbConnect ()
  {
    $con = mysql_connect( HOST, USER, PASSWORD);
     if (!$con) {
     die('Could not connect: ' . mysql_error());
    }
	mysql_select_db(DB_NAME, $con);
	 
  }

settings.php

function editTemplate ()
 {
      if ($handle = opendir('theme/')) 
	    {
          echo '<ul><form id="form1" name="form1" method="post" action="">';
          while (false !== ($file = readdir($handle))) 
	        {
              if ($file != "." && $file != "..") 
	            {
                  echo '<li><input type="radio" name="template" value="'.$file.'" />'.$file.'</li>';
                }
            }     echo '<input type="submit"  value="OK" />';
	              echo '</form>';
	              echo '</ul>';
                  closedir($handle);
                  if (isset($_POST['template']))
                    {
                      $template = $_POST['template'];
                      sib_dbConnect ();
                      mysql_query("UPDATE sib_settings SET site_template ='$template'");
                    }
					 
        }
    }
function getTemplate () {
sib_dbConnect ();
$result = mysql_query("SELECT site_template FROM sib_settings");

while($row = mysql_fetch_array($result))
  {
   $name = $row['site_template'];
  }

require_once('theme/'.$name.'/'.'index.php');
}

global.php

require_once ('database.php');
require_once ('settings.php');

2. NOW Create a new folder and set name theme and isert you theme.


3. Create a new file and set name index.php

require_once('lib/global.php');

getTemplate ();

3. Create a new file and set name edit_template.php

include ('lib/settings.php');
include ('lib/database.php');

editTemplate ();

4. Now create a database TEST

Database: `test`

CREATE TABLE IF NOT EXISTS `sib_settings` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `site_template` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

--
-- Dumping data for table `sib_settings`
--

INSERT INTO `sib_settings` (`id`, `site_template`) VALUES
(1, 'red');

That's all you can if you want to expand the script or add the proposal.
You can download for free

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.