ea-Geiercode-base
[ class tree: ea-Geier ] [ index: ea-Geier ] [ all elements ]

Source for file install.inc.php

Documentation is available at install.inc.php

  1. <?php 
  2. /**
  3.  * php functions for installation support
  4.  *
  5.  * LICENSE:
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the
  13.  * GNU General Public License for more details.
  14.  * You should have received a copy of the GNU General Public License along
  15.  * with this program; if not, write to the Free Software Foundation, Inc.,
  16.  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17.  *
  18.  * @package       ea-Geier
  19.  * @subpackage code/base
  20.  * @author       m2mtech <tech@m2m.at>
  21.  * @copyright  2007 m2m server software gmbh
  22.  * @license       http://www.gnu.org/licenses/gpl.html GNU General Public License Version 2
  23.  * @version       $Id: install.inc.php 148 2007-09-07 16:02:29Z m2mtech $
  24.  * @link       http://www.ea-geier.at/
  25.  */
  26.  
  27. /**
  28.  * database functions for installation support
  29.  */
  30. require_once('code/base/install.db.php');
  31.  
  32. /**
  33.  * html functions for installation support
  34.  */
  35. require_once('code/base/install.html.php');
  36.  
  37. /**
  38.  * first installation
  39.  *
  40.  * @param    array    basic configuration
  41.  */
  42. function eaInstall(&$conf) {
  43.     if (!eaCheckSmartyFolder()) exit;
  44.     
  45.     $in = new eaInput();
  46.     
  47.     $in->get['state'] = 'install';
  48.     
  49.     $in->options = array();
  50.     $opt =& $in->options;
  51.     $opt['db'] = array('mysqlt' => 'MySQL');
  52.  
  53.     $post =& $in->post;
  54.  
  55.     if (isset($_POST['buttonInstall'])) {
  56.  
  57.         $vars = array('p:abc:abc', 'p:txt:txt,pass', 'p:mail:mail');
  58.         $in->check($vars);
  59.         
  60.         if (!$in->error) {
  61.             $dsn = $post['abcDBType'] . '://' . $post['txtUser'] . ':' . $post['txtPass'] . '@' . $post['txtServer'] . '/' . $post['txtDB'];
  62.             $conf['dsn'] = $dsn;
  63.  
  64.             $dbError = false;
  65.             if (dbCreateSystemTables($conf)) {
  66.                 // connect to db
  67.                 $db = new eaDB($conf);
  68.                 if (!$db->error()) {
  69.                     $user = array('mail' => $post['mailAdmin'], 'pw' => $post['passAdmin'], 'name' => 'Admin');
  70.                     $db->createUser($user);                    
  71.                     $admin = $post['mailAdmin'];                    
  72.                 } else $dbError = true;
  73.             } else $dbError = true;
  74.                         
  75.             if ($dbError) { // given database settings are wrong
  76.                 $vars = array('abcDBType', 'txtUser', 'txtPass', 'txtServer', 'txtDB');
  77.                 foreach ($vars as $var) $in->error[$var] = true;
  78.             } else {
  79.                 // prepare config file
  80.                 $template = file('config/config.dist.php');
  81.                 $comment = false;
  82.                 
  83.                 $vars = array('dsn' => 'driver://user:password@server/database', 'admin' => 'admin@ea-geier.at');
  84.                 foreach ($vars as $var => $pattern)
  85.                     $vars[$var] = '/' . preg_quote($pattern, '/') . '/';
  86.                 
  87.                 foreach ($template as $line) { // parse file (simple comments are stripped)
  88.                     if (($pos = strpos($line, '*/')) !== false) {
  89.                         $line = substr($line, $pos + 2);
  90.                         $comment = false; 
  91.                     }
  92.                     if ($comment) continue;
  93.                     if (($pos = strpos($line, '/*')) !== false) { 
  94.                         $line = substr($line, 0, $pos);
  95.                         $comment = true; 
  96.                     }
  97.                     if (($pos = strpos($line, '//')) !== false) 
  98.                         if (!preg_match('/\'.*\/\/.*\'||\".*\/\/.*\"/', $line)) {
  99.                             $line = substr($line, 0, $pos);        
  100.                     }
  101.                     if (!trim($line)) continue;
  102.  
  103.                     // now replace
  104.                     foreach ($vars as $var => $pattern) 
  105.                         $line = preg_replace($pattern, $$var, $line); 
  106.                         
  107.                     $file[] = $line;
  108.                 }
  109.                 
  110.                 if (isset($file)) $post['configfile'] = $file;
  111.                 
  112.             }
  113.         }
  114.     }    
  115.     
  116.     if (!isset($post['txtServer'])) $post['txtServer'] = 'localhost';
  117.     
  118.     eaHTMLOutput($in);
  119.     
  120.     exit;    
  121. }
  122.  
  123. /**
  124.  * check if smarty folders are available and configured correctly
  125.  *
  126.  * @return    boolean status
  127.  */
  128. function eaCheckSmartyFolder() {
  129.  
  130.     // check smarty folders
  131.     $bad = array();
  132.     $vars = array(eaSMARTY_TMP . 'templates_c', eaSMARTY_TMP . 'cache');
  133.     foreach ($vars as $var)
  134.         if (!is_writeable($var)) $bad[] = $var;
  135.  
  136.     if (!$bad) return true;
  137.     
  138.     // get languages
  139.     $lang = array();
  140.     $dir = dir(eaSMARTY_LANG); 
  141.     while (false !== ($file = $dir->read()))
  142.         if (preg_match('/^[a-z]{2}$/', $file)) $lang[] = $file;
  143.     $dir->close();
  144.  
  145.     // show all languages
  146.     echo '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>EA-Geier - Verzeichnisfehler</title><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body>';
  147.     foreach ($lang as $l) {
  148.         $file = eaSMARTY_LANG . $l . '/install.ini';
  149.         if (!is_file($file)) continue;
  150.  
  151.         $file = file($file);
  152.         $match = false;
  153.         foreach ($file as $line) if 
  154.             (preg_match('/([a-z]+)=(.+)/i', $line, $match)) 
  155.                 $ini[$match[1]] = $match[2];
  156.  
  157.         echo '<div style="float: left; padding: 1em;">' . $ini['pleasecheckfolders'] . '<br /><pre>';
  158.         foreach ($bad as $file) echo $file . '<br />';
  159.         echo '</pre>' . $ini['examplecheckfolders'] . '<br /><pre>';            echo 'cd <i>[' . $ini['patheageier'] . ']</i><br />';
  160.         foreach ($bad as $file) echo 'chmod 707 ' . $file . '<br />';
  161.         echo '</pre><hr /></div>';
  162.     }
  163.         
  164.     exit;
  165. }
  166.  
  167. /**
  168.  * update system configuration
  169.  *
  170.  * @param    eaDB    database
  171.  * @return    boolean status
  172.  */
  173.  function eaUpdate(&$db) {
  174.      dbUpdateSystemTables($db);
  175.      dbUpdateClientTables($db);
  176.  }
  177.  
  178.  
  179. ?>

Documentation generated on Sun, 09 Sep 2007 17:09:03 +0200 by phpDocumentor 1.3.1