<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 2005-2006 ARMIA INC                                    |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts EasyCreate 1.1                 |
// +----------------------------------------------------------------------+
// | Authors: sudheesh<sudheesh@armia.com>      		              |
// |          									                          |
// +----------------------------------------------------------------------+
include "includes/session.php";
include "includes/config.php";
include "includes/function.php";
$tempsiteid = addslashes($_GET['tempsiteid']);
$errormessage = "";
if ($_GET['type'] == "new") {
    $_SESSION['session_edittype'] = "new";
} else if ($_GET['type'] == "edit") {
    $_SESSION['session_edittype'] = "edit";
}
if ($_GET["go"] == "true") {
    $_SESSION["session_gbackurlforpageeditor"] = $_SESSION["gbackurl"];
} else {
    $_SESSION["session_gbackurlforpageeditor"] = "editsitepageoption.php?urltype=back";
}
/* Check whether the site published or not. */
if ($_GET['type'] == "new" or $_SESSION['session_edittype'] == "new") {
    /* check for tempsiteid passes as GET parameter.otherwsie set tempsiteid as 'session_currenttempsiteid'.
     * when this page calls for the first time $tempsiteid will be the tempsiteid  passed as GET variable to this page.
     */
    if (($_SESSION['session_edittype'] == "new") and ($tempsiteid == "")) {
        $tempsiteid = $_SESSION['session_currenttempsiteid'];
    }
    $qry = "select * from tbl_tempsite_mast where vtype='simple' and ntempsite_id='" . $tempsiteid . "' and nuser_id='" . $_SESSION["session_userid"] . "'";
    $rs = mysql_query($qry);
    if (mysql_num_rows($rs) > 0) {
        $row = mysql_fetch_array($rs);
        $_SESSION['session_currenttempsiteid'] = $row['ntempsite_id'];
        $_SESSION['session_currenttemplateid'] = $row['ntemplate_id'];
        $_SESSION['session_published'] = "no";
        $_SESSION['session_buildtype'] = "simple";
        $_SESSION['session_sitename'] = $row['vsite_name'];
        $_SESSION['session_siteid'] = "";
        if ($row['vlinks'] != "") {
            $_SESSION['session_pageadded'] = "yes";
        } else {
            $_SESSION['session_pageadded'] = "no";
        }
        if ($row['vlogo'] != "") {
            $_SESSION['session_logoadded'] = "yes";
        } else {
            $_SESSION['session_logoadded'] = "no";
        }
        if (!is_dir("./workarea/tempsites/" . $_SESSION['session_currenttempsiteid'])) {
            $errormessage = "Sites removed.please contact the administartor.";
        } else if (!is_dir("./sitepages/tempsites/" . $_SESSION['session_currenttempsiteid'])) {
            $errormessage = "Site pages removed.please contact the administartor.";
        } else {
            if ($_SESSION['session_edittype'] == "")
                $_SESSION['session_edittype'] = "new";
        }
    } else {
        $errormessage = "Invalid option.";
    }
} else if ($_GET['type'] == "edit" or $_SESSION['session_edittype'] == "edit") {
    if (($_SESSION['session_edittype'] == "edit") and ($tempsiteid == "")) {
        $tempsiteid = $_SESSION['session_siteid'];
    }
    $qry = "select * from tbl_site_mast where vtype='simple' and nsite_id='" . $tempsiteid . "' and nuser_id='" . $_SESSION["session_userid"] . "'";
    // echo "newqry==".$qry;
    $rs = mysql_query($qry);
    if (mysql_num_rows($rs) > 0) {
        $row = mysql_fetch_array($rs);
        $_SESSION['session_siteid'] = $row['nsite_id'];
        $_SESSION['session_currenttemplateid'] = $row['ntemplate_id'];
        $_SESSION['session_published'] = "yes";
        $_SESSION['session_buildtype'] = "simple";
        $_SESSION['session_sitename'] = $row['vsite_name'];
        $_SESSION['session_currenttempsiteid'] = "";
        if ($_SESSION['session_edittype'] == "")
            $_SESSION['session_edittype'] = "edit";
    } else {
        $errormessage = "Site Does not exist.";
    }
} else {
    $errormessage = "Invalid option.";
}
$tmpsiteid = $_SESSION['session_currenttempsiteid'];
$templateid = $_SESSION['session_currenttemplateid'];
$userid = $_SESSION["session_userid"];
$siteid = $_SESSION['session_siteid'];
/* when integration manager calls this page
 * $_GET["go"] will be true.so it will be automaticaly redirected to pageditor.php
 */
if ($_POST['subback'] == "Back") {
    header("location:sitemanager.php");
    exit;
} else if ($_POST['subedittype'] == "Go" || $_GET["go"] == "true") {
    if ($_SESSION['session_published'] == "yes") {
        if ($_POST['editoption'] == "2") {
            SaveSitePreview($userid, $templateid, $tmpsiteid, "$siteid", "Yes", ".", "EditSiteDetails");
            header("location:getsitedetail_foredit.php");
            exit;
        } else if ($_POST['editoption'] == "3") {
            SaveSitePreview($userid, $templateid, "", "$siteid", "Yes", ".", "EditLinks");
            header("location:addlinks_edit.php");
            exit;
        } else if ($_POST['editoption'] == "4" || $_GET["go"] == "true") {
            SaveSitePreview($userid, $templateid, "", "$siteid", "Yes", ".", "EditPages");
            if ($_GET["page"] != "") {
                $pg = $_GET["page"];
                if ($pg == "guestbook") {
                    header("location:./simpleIEeditor/pageeditor.php?page=$pg&pagetype=Guestbook&");
                } else {
                    header("location:./simpleIEeditor/pageeditor.php?page=$pg");
                }
            } else {
                header("location:./simpleIEeditor/pageeditor.php");
            }
            exit;
        } else if ($_POST['editoption'] == "5") {
            SaveSitePreview($userid, $templateid, "", "$siteid", "Yes", ".", "EditPages");
            $_SESSION['session_paymentmode'] = "success";
            header("location:./downloadsite.php");
            exit;
        }
    } else {
        if ($_POST['editoption'] == "2") {
            SaveSitePreview($userid, $templateid, $tmpsiteid, "", "No", ".", "EditSiteDetails");
            header("location:getsitedetail_foredit.php");
            exit;
        } else if ($_POST['editoption'] == "3") {
            SaveSitePreview($userid, $templateid, $tmpsiteid, "", "No", ".", "EditLinks");
            header("location:addlinks_edit.php");
            exit;
        } else if ($_POST['editoption'] == "4" || $_GET["go"] == "true") {
            SaveSitePreview($userid, $templateid, $tmpsiteid, "", "No", ".", "EditPages");
            if ($_GET["page"] != "") {
                $pg = $_GET["page"];
                if ($pg == "guestbook") {
                    header("location:./simpleIEeditor/pageeditor.php?page=$pg&pagetype=Guestbook&");
                } else {
                    header("location:./simpleIEeditor/pageeditor.php?page=$pg");
                }
            } else {
                header("location:./simpleIEeditor/pageeditor.php");
            }
            exit;
        } else if ($_POST['editoption'] == "6") {
            SaveSitePreview($userid, $templateid, $tmpsiteid, "", "No", ".", "EditPages");
            $sql12 = "select vname,vvalue from tbl_lookup where vname ='paymentsupport'";
            $result12 = mysql_query($sql12, $con);
            $row12 = mysql_fetch_array($result12);
            $needpaymentsupport = $row12['vvalue'];
            if ($needpaymentsupport == "no") {

                header("location:./publishpage_free.php?uid=" . $userid . "&tid=" . $tmpsiteid . "&type=simple&style=" . $_SESSION["session_style"] . "&");
                exit;
            } else {
                header("location:" . $_SESSION["session_secureserver"] . "/publishpage.php?uid=" . $userid . "&tid=" . $tmpsiteid . "&type=simple&style=" . $_SESSION["session_style"] . "&");
                exit;
            }
        }
    }
}
include "includes/userheader.php";

?>
<SCRIPT>
    function showpreview(id){
        var leftPos = (screen.availWidth-500) / 2;
        var topPos = (screen.availHeight-400) / 2 ;
        winurl="showfinalpreview.php";
        insertFormWin = window.open(winurl,'','width=' + screen.availWidth + ',height=' + screen.availHeight + ',scrollbars=yes,resizable=yes,titlebar=0,top=' + topPos + ',left=' + leftPos);
    }
</SCRIPT>
<div class="common_box">
    <table width="100%"  border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td  valign="top" align=center>
                <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td >
                            <!-- Main section starts here-->
                            <form name=frmEditOption method=post >
                                <table width="100%" border=0 align=center>
                                    <?php
                                    if ($errormessage == "") {
                                        /* 1.add/remove page button will be visible only when user entered his/her site details
                                         *  2.edit site content will be visible only when he/she added pages for the site
                                         *  ftp/zip will be visible only when user complete step1 and step2
                                         */
                                        ?>
                                        <tr>
                                            <td>
                                                <table width="60%" border=0>
                                                    <?php if ($_SESSION['session_edittype'] == "new") { ?>
                                                     <!--<tr>
                                                                                 <td align=left class=maintext>
                                                                                       <input type=radio name="editoption" id="editoption" checked value="1">Edit template
                                                                                     </td>
                                                                              </tr>-->
                                                    <?php } ?>
                                                                                                
                                                    <tr>
                                                        <td align=left class=maintext>
                                                            <input type=radio name="editoption" id="editoption" value="2">Edit details of your site
                                                        </td>
                                                    </tr>
                                                                                                 
                                                    <tr>
                                                        <td align=left class=maintext>
                                                            <?php if ($_SESSION['session_edittype'] == "edit") { ?>
                                                                <input type=radio name="editoption" id="editoption" value="3">Add or remove pages from your site
                                                            <?php } else if ($_SESSION['session_edittype'] == "new" and $_SESSION['session_logoadded'] == "yes") { ?>
                                                                <input type=radio name="editoption" id="editoption" value="3">Add or remove pages from your site
                                                            <?php } ?>
                                                                                                          
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td align=left class=maintext>
                                                            <?php if ($_SESSION['session_edittype'] == "edit") { ?>
                                                                <input type=radio name="editoption" id="editoption" value="4">Edit the contents of individual pages
                                                            <?php } else if ($_SESSION['session_edittype'] == "new" and $_SESSION['session_pageadded'] == "yes" and $_SESSION['session_logoadded'] == "yes") { ?>
                                                                <input type=radio name="editoption" id="editoption" value="4">Edit the contents of individual pages
                                                            <?php } ?>
                                                                                                  
                                                                                                  
                                                        </td>
                                                    </tr>
                                                    <?php
                                                    if ($_SESSION['session_edittype'] == "edit") {
                                                        $qry = "select vvalue from tbl_lookup where vname='user_publish_option'";
                                                        $result = mysql_query($qry);
                                                        $row = mysql_fetch_array($result);
                                                        $ftpzip = $row["vvalue"];
                                                        ?>
                                                        <tr>
                                                            <td align=left class=maintext>
                                                                <input type=radio name="editoption" id="editoption"  value="5" checked><?php echo $ftpzip; ?>
                                                            </td>
                                                        </tr>
                                                    <?php } ?>
                                                    <?php if ($_SESSION['session_edittype'] == "new" and $_SESSION['session_pageadded'] == "yes" and $_SESSION['session_logoadded'] == "yes") { ?>
                                                        <tr>
                                                            <td align=left class=maintext>
                                                                <input type=radio name="editoption" id="editoption"  value="6" checked>Publish your site using  FTP/ZIP/SUBFOLDER
                                                            </td>
                                                        </tr>
                                                    <?php } ?>
                                                                                                
                                                                                                
                                                </table>
                                                                           
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align=center>
                                                <input class=button type=submit name="subedittype" Value="Go" >
                                                <?php if ($_SESSION['session_edittype'] == "edit") { ?>
                                                    <input class=button type=button  name="subedittype" Value="Preview" onclick="showpreview(this.id);">
                                                <?php } else if ($_SESSION['session_edittype'] == "new" and $_SESSION['session_pageadded'] == "yes" and $_SESSION['session_logoadded'] == "yes") { ?>
                                                    <input class=button type=button  name="subedittype" Value="Preview" onclick="showpreview(this.id);">
                                                <?php } ?>
                                                <input class=button type=submit name="subback" Value="Back">
                                            </td>
                                                                   
                                        </tr>
                                    <?php } else { ?>
                                        <tr>
                                            <td class=errormessage>
                                                <?php echo $errormessage; ?>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <input class=button type=submit name="subback" Value="Back">
                                            </td>
                                        </tr>
                                    <?php } ?>
                                </table>
                            </form>
                            <!-- Main section ends here-->
                        </td>
                    </tr>
                    <tr><td>&nbsp;</td></tr>
                    <tr><td>&nbsp;</td></tr>
                </table>
            </td>
        </tr>
    </table>
</div>
<?php
include "includes/userfooter.php";
?>