<?php
/***************************************************************************
* websites.php
* -------------------
* begin : mar, ago 28, 2007
* copyright : (C)
* email : hide@address.com
* Desc : Website management
*
*
***************************************************************************/
define('IN_ADSERVER', true);
include_once("./inc/common.inc.php");
checkLogin($web_address);
/* Declare the TPL */
$websites_Tpl = new tpl($s_path_Tpl . "/websites.tpl");
//Required variables
$s_Errors = "";
$s_Id_Cat_Is = "";
$s_Cats_Display = "";
$s_Doing_Text = "add_Site";
$s_Doing_Value = $_lang['sites_Doing_1'];
$s_Website_Name = "";
//Delete Web Site
if(isset($_POST['delete_Site'])){
$q = "
DELETE FROM ".$db_Pre."websites
WHERE id_Website = ".$_POST['modify_Site_Id']."
AND id_User = ".$session['id_User']."
";
$q_Delete_Website = mysql_query($q) or die("Unable to Delete Website: " . mysql_error());
$s_Msg = $_lang['sites_Msg_Deleted'];
}
//Add new website or modify it
if((isset($_POST['add_Site']) || isset($_POST['modify_Site'])) && !isset($_POST['delete_Site']) && $_POST['website'] != ""){
//Get all the categories that it will NOT show
$categories_Dont = "";
for($i = 0; $i <= $_POST['cat_Num']; $i++){
if(isset($_POST[$i])){
if($i > 0 && $categories_Dont != ""){
$categories_Dont .= "::";
}
$categories_Dont .= $i;
}
}
if(isset($_POST['add_Site'])){
$q = "
INSERT INTO ".$db_Pre."websites
(name, id_User, timestamp, id_Cat_Dont, id_Cat_Is)
VALUES ('".$_POST['website']."',".$session['id_User'].",".time().",'".$categories_Dont."', ".$_POST['id_Cat_Is'].")
";
$q_Add_Website = mysql_query($q) or die("Unable to Create New Website: " . mysql_error());
$s_Msg = $_lang['sites_Msg_Created'];
}
else if(isset($_POST['modify_Site'])){
$q = "
UPDATE ".$db_Pre."websites
SET name ='".$_POST['website']."',
id_Cat_Dont = '".$categories_Dont."',
id_Cat_Is = ".$_POST['id_Cat_Is']."
WHERE id_Website = ".$_POST['modify_Site_Id']."
AND id_User = ".$session['id_User']."
";
$q_Mod_Website = mysql_query($q) or die("Unable to Modify Website: " . mysql_error());
$_POST['mod_Site'] = $_POST['view_Site'] = $_POST['modify_Site_Id'];
$s_Msg = $_lang['sites_Msg_Mod'];
}
}
//Get websites
$s_Option_Sites = "";
$q = "
SELECT id_Website, name
FROM ".$db_Pre."websites
WHERE id_User = ".$session['id_User']."
";
$q_Get_Websites = mysql_query($q) or die("Unable to Get WebSites: " . mysql_error());
while($row = mysql_fetch_array($q_Get_Websites, MYSQL_ASSOC)){
$s_Option_Sites .= "<option value='".$row['id_Website']."'>".$row['name']."</option>";
}
//View a website
if(isset($_POST['view_Site']) && $_POST['mod_Site'] != 0){
$q = "
SELECT *
FROM ".$db_Pre."websites
WHERE id_Website = ".$_POST['mod_Site']."
";
$q_Get_Websites = mysql_query($q) or die("Unable to Get WebSites: " . mysql_error());
while($row = mysql_fetch_array($q_Get_Websites, MYSQL_ASSOC)){
$s_Website_Name = $row['name'];
$s_Website_Cats_Dont = $row['id_Cat_Dont'];
$s_Website_Cat_Is = $row['id_Cat_Is'];
}
$a_Cats_D = explode("::", $s_Website_Cats_Dont);
$s_Doing_Text = "modify_Site";
$s_Doing_Value = $_lang['sites_Doing_2'];
}
else{
$a_Cats_D = "";
}
//Select all categories
$q = "
SELECT *
FROM ".$db_Pre."categories
WHERE active = 1
";
$q_Categories = mysql_query($q) or die("Unable to Get Category List: " . mysql_error());
if(mysql_num_rows($q_Categories) > 0){
while($row = mysql_fetch_array($q_Categories, MYSQL_ASSOC)){
$s_Id_Cat_Is .= "<option value='".$row['id_Category']."' ".($s_Website_Cat_Is == $row['id_Category'] ? "selected" : "" ).">".$row['name']."</option>";
static $cats_Num = 0;
$s_Cats_Display .= $row['name'] . " <input type='checkbox' name='".$row['id_Category']."'";
//Categories restricted
if($a_Cats_D != ""){
$s_Cats_Display .= (in_array($row['id_Category'], $a_Cats_D) ? "checked" : "");
}
$cats_Num++;
//Close them
$s_Cats_Display .= ">";
}
}
else{
$s_Id_Cat_Is = $_lang['sites_No_Cats'];
}
$s_Warning = $s_Msg;
$a_Websites = array(
"{WEBSITES_HELP_TITLE}" => $_lang['sites_Help_Title'],
"{WEBSITES_HELP_TEXT}" => $_lang['sites_Help_Text'],
"{WEBSITES_SELECT}" => $_lang['sites_Select'],
"{WEBSITES_SITES_OPTIONS}" => $s_Option_Sites,
"{WEBSITES_VIEW}" => $_lang['sites_View'],
"{WEBSITES_CREATE}" => $_lang['sites_Create'],
"{WEBSITES_ADD}" => $_lang['sites_Add'],
"{WEBSITES_WEBSITE_NAME}" => $s_Website_Name,
"{WEBSITES_CATEGORIES}" => $_lang['sites_Cat'],
"{WEBSITES_CAT_IS}" => $s_Id_Cat_Is,
"{WEBSITES_CATS_NUM}" => $cats_Num,
"{WEBSITES_SITE_ID_MOD}" => (isset($_POST['mod_Site']) ? $_POST['mod_Site'] : ""),
"{WEBSITES_DOING_TEXT}" => $s_Doing_Text,
"{WEBSITES_DOING_VALUE}" => $s_Doing_Value
);
/* If users can restrict categories */
if(get_User_Settings($session['id_User'], 'restrict_Cats_Display') == 1){
$a_Rest_Cats = array(
"{WEBSITES_REST_CATS}" => $_lang['sites_Rest_Cats'],
"{WEBSITES_REST_CATS_NOTE}" => $_lang['sites_Rest_Cats_Note'],
"{WEBSITES_CATS_DISPLAY}" => $s_Cats_Display
);
$websites_Tpl->rBlock($a_Rest_Cats, "REST_CATS");
}
else{
$websites_Tpl->hideBlock("REST_CATS");
}
if(isset($_POST['view_Site']) && $_POST['mod_Site'] != 0){
/*
$a_Delete = array(
"{WEBSITES_DELETE}" => $_lang['sites_Delete']
);
$websites_Tpl->rBlock($a_Rest_Cats, "DELETE");
*/
}
else{
$websites_Tpl->hideBlock("DELETE");
}
/* Replace main TPL */
$websites_Tpl->rBlock($a_Websites, "");
$websites_Tpl->localize_It($_lang);
include_once("./header.inc.php");
/* Print the tpl */
$websites_Tpl->print_Tpl();
include_once("./footer.inc.php");
?>