<?php
/**
 * This is the ArticleManager install file for Boost
 *
 * @version $Id: install.php,v 1.7 2004/11/23 02:07:37 adarkling Exp $
 * @author Eloi George <eloi@NOSPAM.bygeorgeware.com>
 * @module Article Manager
 */
if (!$_SESSION["OBJ_user"]->isDeity())
{
    header("location:index.php");
    exit();
}

if(version_compare($GLOBALS['core']->version, "0.10.0") < 0) 
{
 $content .= "This module requires a phpWebSite core version of 0.10.0 or greater to install.<br />";
 $content .= "<br />You are currently using phpWebSite core version " . $GLOBALS['core']->version . ".<br />";
} else {

/* Don't overwrite the tables for this module if they're already there */
if ($GLOBALS['core']->sqlTableExists("mod_article", true)
        && $GLOBALS['core']->sqlTableExists("mod_article_sections", true)
        && $GLOBALS['core']->sqlTableExists("mod_article_config", true)   )
{
    $content .= "All Article Manager tables already exist.  Old data will be used.<br />";
    $olddata = true;
}
else
{
    $content .= "This is a new installation of Article Manager.<br />";
    $olddata = false;
}
    
/* If the old tables are already there or if new ones have sucessfully been written... */
if ($olddata || $GLOBALS['core']->sqlImport(PHPWS_SOURCE_DIR . "mod/article/boost/install.sql", TRUE)) 
{
    if (!$olddata)
        $content .= "All ArticleManager tables successfully written.<br />";
    
    CLS_Help::setup_help("article");

    function makedir ($dir)
    {
      $dirname = $GLOBALS['core']->home_dir . $dir;
      if (is_dir($dirname))
      {
        $text = 'Article Manager image directory '.$dirname.' already exists!<br />';
        return;
      }
      mkdir($dirname);
      if (is_dir($dirname))
      {
        $text = 'Article Manager image directory '.$dirname.' successfully created!<br />';
        chmod($dirname,0777);
      }
      else
        $text = 'We could not create the image archive: '. $dirname
                . '<br />You\'ll have to do this manually!<br />';
      return $text;
    }
    /* Create the main image directory */
    $content .= makedir('images/article');
    /* Create the image library directory */
    $content .= makedir('images/article/library');
    /* Create the first image storage directory */
    $content .= makedir('images/article/1');
    /* Create the image archive directory */
    $content .= makedir('images/article/old');
    /* Create import directories for PageMaster & Announce */
    $content .= makedir('images/article/PM');
    $content .= makedir('images/article/ANN');

    $status = 1;
} 
else
    $content .= 'There was a problem writing to the database.<br />';
}
?>