<?php

include "../include/config.php";
include "../include/function.php";
if ($_REQUEST['submit']) {
    $sql = "update signup set\n                                email = '{$_REQUEST['email']}',\n                                fname = '{$_REQUEST['fname']}',\n                                lname = '{$_REQUEST['lname']}',\n                                city = '{$_REQUEST['city']}',\n                                country = '{$_REQUEST['country']}',\n                                website = '{$_REQUEST['website']}',\n                                occupation = '{$_REQUEST['occupation']}',\n                                company = '{$_REQUEST['company']}',\n                                school = '{$_REQUEST['school']}',\n                                interest_hobby = '{$_REQUEST['interest_hobby']}',\n                                fav_movie_show = '{$_REQUEST['fav_movie_show']}',\n                                fav_book = '{$_REQUEST['fav_book']}',\n                                fav_music = '{$_REQUEST['fav_music']}',\n                                aboutme = '{$_REQUEST['aboutme']}',\n                                emailverified = '{$_REQUEST['emailverified']}',\n                                account_status = '{$_REQUEST['account_status']}'\n                        where UID={$_REQUEST['uid']}";
    $conn->execute($sql);
    header("Location: useredit.php?action=edit&uid={$_REQUEST['uid']}&page={$_REQUEST['page']}&msg=User+information+updated+successfully");
}
$rs = $conn->execute("select * from signup where UID={$_REQUEST['uid']}");
$user = $rs->getrows();
STemplate::assign('country_box', country_box($user[0]['country']));
if ($user[0]['emailverified'] == "yes") {
    $yessel = "selected";
} else {
    $nosel = "selected";
}
$email_ver_box = "<option value='yes' {$yessel}>Yes</option>\n                          <option value='no' {$nosel}>No</option>";
STemplate::assign('email_ver_box', $email_ver_box);
if ($user[0]['account_status'] == "Active") {
    $activesel = "selected";
} else {
    $inactivesel = "selected";
}
$account_status_box = "<option value='Active' {$activesel}>Active</option>\n                          <option value='Inactive' {$inactivesel}>Inactive</option>";
STemplate::assign('account_status_box', $account_status_box);
if ($_REQUEST[msg] != "") {
    $msg = $_REQUEST[msg];
}
Stemplate::assign('user', $user[0]);
Stemplate::assign('err', $err);
if ($_REQUEST['submit']) {
    $sql = "update group_own set\n                                gname = '{$_REQUEST['gname']}',\n                                keyword = '{$_REQUEST['keyword']}',\n                                gdescn = '{$_REQUEST['gdescn']}',\n                                gurl = '{$_REQUEST['gurl']}',\n                                type = '{$_REQUEST['type']}',\n                                featured = '{$_REQUEST['featured']}',\n                                gupload = '{$_REQUEST['gupload']}',\n                                gposting = '{$_REQUEST['gposting']}',\n                                gimage = '{$_REQUEST['gimage']}'\n                                where GID={$_REQUEST['gid']}";
    $conn->execute($sql);
    if (count($_REQUEST[channel]) < 1 or count($_REQUEST[channel]) > 3) {
        $err = "Please check (1 to 3) channel/s.";
    } else {
        $sql = "update group_own set\n                                        channel = '0|" . implode("|", $_REQUEST[channel]) . "|0'\n                                where GID={$_REQUEST['gid']}";
        $conn->execute($sql);
    }
    if ($err == "") {
        header("Location: groupedit.php?action=edit&gid={$_REQUEST['gid']}&page={$_REQUEST['page']}&msg=User+information+updated+successfully");
    }
}
$rs = $conn->execute("select * from group_own where GID={$_REQUEST['gid']}");
$group = $rs->getrows();
STemplate::assign('country_box', country_box($group[0]['country']));
if ($group[0]['type'] == "public") {
    $pubsel = "selected";
} elseif ($group[0]['type'] == "private") {
    $prisel = "selected";
} elseif ($group[0]['type'] == "protected") {
    $prosel = "selected";
}
$type_box = "<option value='public' {$pubsel}>Public</option>\n                          <option value='private' {$prisel}>Private</option>\n                          <option value='protected' {$prosel}>Protected</option>";
STemplate::assign('type_box', $type_box);
if ($group[0]['gupload'] == "immediate") {
    $u1sel = "selected";
} elseif ($group[0]['gupload'] == "owner_approve") {
    $u2sel = "selected";
} elseif ($group[0]['gupload'] == "owner_only") {
    $u3sel = "selected";
    if ($rs->recordcount() <= 0) {
        $err = "Invalid key";
    }
    if ($err == "") {
        if (!is_numeric($month) || !is_numeric($day) || !is_numeric($year) || !checkdate($month, $day, $year)) {
            $err = "Upload: Please Provide a valid date.";
        } elseif ($field_address == "") {
            $err = "Upload: Please Provide the location.";
        } elseif ($country == "Select Country") {
            $err = "Please provide Country name.";
        }
        if ($err == "") {
            $sql = "update audio set\n\t\t\t\t\trecord_date='" . $year . "-" . $month . "-" . $day . "',\n\t\t\t\t\tlocation='{$field_address}',\n\t\t\t\t\tcountry='{$country}' WHERE VID=" . $rs->fields[VID];
            $conn->execute($sql);
            if (mysql_affected_rows() >= 1) {
                header("location:{$config['baseurl']}/my_audio.php");
            }
        }
    }
}
STemplate::assign('err', $err);
STemplate::assign('msg', $msg);
STemplate::assign('head_bottom', "musiclinks.tpl");
STemplate::assign('days', days($_POST[day]));
STemplate::assign('months', months($_POST[month]));
STemplate::assign('years', years($_POST[year]));
STemplate::assign('country', country_box($_POST[country]));
STemplate::display('head1.tpl');
STemplate::display('err_msg.tpl');
STemplate::display('upload_success_music.tpl');
STemplate::display('footer.tpl');
                $conn->execute($sql);
                STemplate::assign('vcode', $ran);
                $to = $_REQUEST[email];
                $_SESSION[EMAIL] = $_REQUEST[email];
                $name = $config['site_name'];
                $from = $config['admin_email'];
                $rs = $conn->execute("select * from emailinfo where email_id='verify_email'");
                $subj = $rs->fields['email_subject'];
                $email_path = $rs->fields['email_path'];
                $mailbody = STemplate::fetch($email_path);
                mailing($to, $name, $from, $subj, $mailbody, $bcc = "");
                session_to_db();
            }
        }
    }
}
$sql = "select * from signup WHERE UID={$_SESSION['UID']}";
$rs = $conn->execute($sql);
$date = explode("-", $rs->fields[bdate]);
STemplate::assign('err', $err);
STemplate::assign('msg', $msg);
STemplate::assign('days', days($date[2]));
STemplate::assign('months', months($date[1]));
STemplate::assign('years', years($date[0]));
STemplate::assign('country', country_box($_REQUEST[country]));
STemplate::assign('answers', $rs->getarray());
STemplate::assign('head_bottom', "homelinks.tpl");
STemplate::display('head1.tpl');
STemplate::display('err_msg.tpl');
STemplate::display('my_profile.tpl');
STemplate::display('footer.tpl');
            $add .= "record_date='{$recorddate}', ";
        }
        if ($_REQUEST[country] != "Select Country") {
            $add .= "country='{$_REQUEST['country']}', ";
        }
        $sql = "update video set\n\t\t\t\t\ttitle='{$_REQUEST['vtitle']}',\n\t\t\t\t\tdescription='{$_REQUEST['vdescription']}',\n\t\t\t\t\tfeaturedesc='{$_REQUEST['featuredesc']}',\n\t\t\t\t\tkeyword='{$_REQUEST['vkeyword']}',\n\t\t\t\t\tchannel='0|{$listch}|0',\n\t\t\t\t\ttype='{$_REQUEST['video_privacy']}',\n\t\t\t\t\tlocation='{$_REQUEST['field_address']}',\n\t\t\t\t\t{$add}\n\t\t\t\t\tbe_comment='{$_REQUEST['allow_comments']}',\n\t\t\t\t\tbe_rated='{$_REQUEST['allow_ratings']}',\n\t\t\t\t\tembed='{$_REQUEST['allow_embed']}'\n\t\t\t\t\tWHERE VID={$_REQUEST['VID']}";
        $conn->execute($sql);
        $vid = mysql_insert_id();
        $vdoname = $vid . "." . $ph;
        if (mysql_affected_rows() >= 1) {
            $msg = "Video info updated successfully!";
        }
    }
}
$sql = "select * from video WHERE VID={$_REQUEST['VID']}";
$rs = $conn->execute($sql);
$date = explode("-", $rs->fields[record_date]);
$chid = explode("|", $rs->fields[channel]);
STemplate::assign('err', $err);
STemplate::assign('msg', $msg);
STemplate::assign('chid', $chid);
STemplate::assign('days', days($date[2]));
STemplate::assign('months', months($date[1]));
STemplate::assign('years', years($date[0]));
STemplate::assign('country', country_box($rs->fields[country]));
STemplate::assign('answers', $rs->getarray());
STemplate::assign('head_bottom', "homelinks.tpl");
STemplate::display('head1.tpl');
STemplate::display('err_msg.tpl');
STemplate::display('my_vdo_edit.tpl');
STemplate::display('footer.tpl');