function process()
 {
     global $LNG;
     $arr = $this->validate_values();
     // Must be stored in a variable before executing an empty condition
     if (empty($arr)) {
         // If there is no error message then execute the query;
         //$this->query();
         // Set a session and log-in the user
         $_SESSION['enrollno'] = $this->enrollno;
         $_SESSION['name'] = $this->name;
         $_SESSION['course'] = $this->course;
         $_SESSION['branch'] = $this->branch;
         $_SESSION['born'] = $this->born;
         $_SESSION['join'] = $this->join;
         //Redirect the user to his personal profile
         //header("Location: ".$this->url."/something");
         // Return (int) 1 if everything was validated
         $x = 1;
         // return $LNG['user_success'];
     } else {
         // If there is an error message
         foreach ($arr as $err) {
             return notificationBox('transparent', $LNG['error'], $LNG["{$err}"], 1);
             // Return the error value for translation file
         }
     }
     return $x;
 }
 function in()
 {
     global $LNG;
     // If an user is found
     if ($this->queryLogIn() == 1) {
         // Set session
         $_SESSION['usernameAdmin'] = $this->username;
         $_SESSION['passwordAdmin'] = md5($this->password);
         // Redirect the user to his personal profile
         // header("Location: ".$this->url."/index.php?a=feed");
     } else {
         // If wrong credentials are entered, unset everything
         $this->logOut();
         return notificationBox('error', $LNG['error'], $LNG['invalid_user_pw']);
     }
 }
 function process()
 {
     global $LNG;
     $arr = $this->validate_values();
     // Must be stored in a variable before executing an empty condition
     if (empty($arr)) {
         // If there is no error message then execute the query;
         //Redirect the user to his personal profile
         //header("Location: ".$this->url."/something");
         // Return (int) 1 if everything was validated
         $x = 1;
         // return $LNG['user_success'];
     } else {
         // If there is an error message
         foreach ($arr as $err) {
             return notificationBox('transparent', $LNG['error'], $LNG["{$err}"], 1);
             // Return the error value for translation file
         }
     }
     return $x;
 }
function PageMain()
{
    global $TMPL, $LNG, $CONF, $db, $loggedIn, $settings;
    if ($settings['captcha']) {
        $TMPL['captcha'] = '<input type="text" name="captcha" placeholder="' . $LNG['captcha'] . '" />
		<span class="welcome-captcha"><img src="' . $CONF['url'] . '/includes/captcha.php" /></span>';
    }
    if (isset($_POST['register'])) {
        // Register usage
        $reg = new register();
        $reg->db = $db;
        $reg->url = $CONF['url'];
        $reg->username = $_POST['username'];
        $reg->password = $_POST['password'];
        $reg->email = $_POST['email'];
        $reg->enrollno = $_POST['enrollno'];
        $reg->captcha = $_POST['captcha'];
        $reg->captcha_on = $settings['captcha'];
        $reg->message_privacy = $settings['mprivacy'];
        $reg->like_notification = $settings['notificationl'];
        $reg->comment_notification = $settings['notificationc'];
        $reg->shared_notification = $settings['notifications'];
        $reg->chat_notification = $settings['notificationd'];
        $reg->friend_notification = $settings['notificationf'];
        $reg->verified = $settings['verified'];
        $reg->email_like = $settings['email_like'];
        $reg->email_comment = $settings['email_comment'];
        $reg->email_new_friend = $settings['email_new_friend'];
        $reg->sound_new_notification = $settings['sound_new_notification'];
        $reg->sound_new_chat = $settings['sound_new_chat'];
        $TMPL['registerMsg'] = $reg->process();
        if ($TMPL['registerMsg'] == 1) {
            if ($settings['mail']) {
                sendMail($_POST['email'], sprintf($LNG['welcome_mail'], $settings['title']), sprintf($LNG['user_created'], $settings['title'], $_POST['username'], $_POST['password'], $CONF['url'], $settings['title']), $CONF['email']);
            }
            header("Location: " . $CONF['url'] . "/index.php?a=feed");
        }
    }
    if (isset($_POST['login'])) {
        // Log-in usage
        $log = new logIn();
        $log->db = $db;
        $log->url = $CONF['url'];
        $log->username = $_POST['username'];
        $log->password = $_POST['password'];
        $log->remember = $_POST['remember'];
        $TMPL['loginMsg'] = notificationBox('transparent', $LNG['error'], $log->in(), 1);
    }
    if (isset($_SESSION['username']) && isset($_SESSION['password']) || isset($_COOKIE['username']) && isset($_COOKIE['password'])) {
        $verify = $loggedIn->verify();
        if ($verify['username']) {
            header("Location: " . $CONF['url'] . "/index.php?a=feed");
        }
    }
    // Start displaying the home-page users
    $result = $db->query("SELECT * FROM `users` WHERE `image` != 'default.png' ORDER BY `idu` DESC LIMIT 10 ");
    while ($row = $result->fetch_assoc()) {
        $users[] = $row;
    }
    $TMPL['rows'] = showUsers($users, $CONF['url']);
    $TMPL['url'] = $CONF['url'];
    $TMPL['title'] = $LNG['welcome'] . ' - ' . $settings['title'];
    $TMPL['ad'] = stripslashes($settings['ad1']);
    $skin = new skin('welcome/content');
    return $skin->make();
}
Beispiel #5
0
 function managePlaylist($id, $type, $data = null)
 {
     global $LNG;
     // Type 0: Return the current playlist info
     // Type 1: Update the current playlist
     // Type 2: Add a new playlist
     if ($type == 2) {
         $data = trim($data);
         // Prepare the statement
         if (strlen($data) == 0) {
             return;
         }
         // Prepare the insertion
         $stmt = $this->db->prepare(sprintf("INSERT INTO `playlists` (`by`, `name`, `public`, `time`) VALUES ('%s', '%s', 1, CURRENT_TIMESTAMP)", $this->db->real_escape_string($this->id), htmlspecialchars(trim(nl2clean($this->db->real_escape_string($data))))));
         // Execute the statement
         $stmt->execute();
         // Save the affected rows
         $affected = $stmt->affected_rows;
         // Close the statement
         $stmt->close();
         if ($affected) {
             // Return the latest added playlist entry
             return $this->playlistEntry($id, 0, 2);
         }
     } elseif ($type == 1) {
         // Strip the white spaces at the beginning/end of the name
         $data['name'] = trim($data['name']);
         // Prepare the statement
         if (strlen($data['name']) == 0) {
             return notificationBox('error', sprintf($LNG['playlist_name_empty']));
         }
         if (strlen($data['description']) > 160) {
             return notificationBox('error', sprintf($LNG['playlist_description'], 160));
         }
         $stmt = $this->db->prepare("UPDATE `playlists` SET `description` = '{$this->db->real_escape_string(htmlspecialchars(trim(nl2clean($data['description']))))}', `name` = '{$this->db->real_escape_string(htmlspecialchars($data['name']))}' WHERE `id` = '{$this->db->real_escape_string($id)}' AND `by` = '{$this->id}'");
         // Execute the statement
         $stmt->execute();
         // Save the affected rows
         $affected = $stmt->affected_rows;
         // Close the statement
         $stmt->close();
         // If there was anything affected return 1
         if ($affected) {
             return notificationBox('success', $LNG['changes_saved']);
         } else {
             return notificationBox('info', $LNG['nothing_changed']);
         }
     } else {
         $query = $this->db->query(sprintf("SELECT `name`,`description` FROM `playlists` WHERE `id` = '%s' AND `by` = '%s'", $this->db->real_escape_string($_GET['id']), $this->id));
         $result = $query->fetch_array();
         return $result;
     }
 }
 function query_array($table, $data)
 {
     global $LNG;
     // Validate the inputs
     $validate = $this->validate_inputs($data);
     if ($validate) {
         return notificationBox('error', $LNG['error'], sprintf($LNG["{$validate[0]}"], $validate[1]));
     }
     // add the born value
     if (isset($data['day']) || isset($data['month']) || isset($data['year'])) {
         $data['born'] = $data['day'] . '/' . $data['month'] . '/' . $data['year'];
     }
     // Unset the day/month/verified values
     unset($data['day']);
     unset($data['month']);
     unset($data['year']);
     // add the join value
     if (isset($data['jyear']) || isset($data['tyear'])) {
         $data['join'] = $data['jyear'] . '-' . $data['tyear'];
     }
     // Unset the values
     unset($data['jyear']);
     unset($data['tyear']);
     // Get the columns of the query-ed table
     $available = $this->getColumns($table);
     foreach ($data as $key => $value) {
         // Check if password array key exist and set a variable if so
         if ($key == 'password') {
             $password = true;
         }
         // Check if all arrays introduced are available table fields
         if (!array_key_exists($key, $available)) {
             $x = 1;
             break;
         }
     }
     // If the password array key exists, encrypt the password
     if ($password) {
         $data['password'] = md5($data['password']);
     }
     $updatedata = '';
     // If all array keys are valid database columns
     if ($x !== 1) {
         $updatedata .= "`first_name` = '" . $data['first_name'] . "',";
         $updatedata .= "`last_name` = '" . $data['last_name'] . "',";
         $updatedata .= "`email` = '" . $data['email'] . "',";
         $updatedata .= "`born` = '" . $data['born'] . "',";
         $updatedata .= "`gender` = '" . $data['gender'] . "',";
         $updatedata .= "`location` = '" . $data['location'] . "',";
         $updatedata .= "`website` = '" . $data['website'] . "',";
         $updatedata .= "`private` = '" . $data['private'] . "',";
         $updatedata .= "`privacy` = '" . $data['privacy'] . "',";
         $updatedata .= "`offline` = '" . $data['offline'] . "',";
         $updatedata .= "`facebook` = '" . $data['facebook'] . "',";
         $updatedata .= "`twitter` = '" . $data['twitter'] . "',";
         $updatedata .= "`gplus` = '" . $data['gplus'] . "',";
         $updatedata .= "`bio` = '" . $data['bio'] . "'";
         // Prepare the statement
         $stmt = $this->db->prepare("UPDATE `{$table}` SET {$updatedata} WHERE `idu` = '{$this->id}'");
         // Execute the statement
         $stmt->execute();
         // Save the affected rows
         $affected = $stmt->affected_rows;
         // Close the statement
         $stmt->close();
         // If the SQL was executed, and the password field was set, save the new password
         if ($affected && $password) {
             if (isset($_COOKIE['password'])) {
                 setcookie("password", $data['password'], time() + 30 * 24 * 60 * 60);
                 // Expire in one month
             } else {
                 $_SESSION['password'] = $data['password'];
             }
         }
         // If there was anything affected return 1
         if ($affected) {
             return notificationBox('success', $LNG['settings_saved'], $LNG['overall_settings_saved']);
         } else {
             return notificationBox('info', $LNG['nothing_changed'], $LNG['general_settings_unaffected']);
         }
     }
 }
Beispiel #7
0
function PageMain()
{
    global $TMPL, $LNG, $CONF, $db, $settings;
    if (isset($_POST['login'])) {
        $logInAdmin = new logInAdmin();
        $logInAdmin->db = $db;
        $logInAdmin->url = $CONF['url'];
        $logInAdmin->username = $_POST['username'];
        $logInAdmin->password = $_POST['password'];
        $TMPL['message'] = $logInAdmin->in();
    }
    if (isset($_SESSION['usernameAdmin']) && isset($_SESSION['passwordAdmin'])) {
        $loggedInAdmin = new loggedInAdmin();
        $loggedInAdmin->db = $db;
        $loggedInAdmin->url = $CONF['url'];
        $loggedInAdmin->username = $_SESSION['usernameAdmin'];
        $loggedInAdmin->password = $_SESSION['passwordAdmin'];
        $loggedIn = $loggedInAdmin->verify();
        if ($loggedIn['username']) {
            // Set the content to true, change the $skin to content
            $content = true;
            $TMPL_old = $TMPL;
            $TMPL = array();
            $TMPL['url'] = $CONF['url'];
            if ($_GET['b'] == 'security') {
                // Security Admin Tab
                $skin = new skin('admin/security');
                $page = '';
                if (!empty($_POST)) {
                    $updateSettings = new updateSettings();
                    $updateSettings->db = $db;
                    $updated = $updateSettings->query_array('admin', $_POST);
                    if ($updated == 1) {
                        header("Location: " . $CONF['url'] . "/index.php?a=admin&b=security&m=s");
                    } else {
                        header("Location: " . $CONF['url'] . "/index.php?a=admin&b=security&m=i");
                    }
                }
                if ($_GET['m'] == 's') {
                    $TMPL['message'] = notificationBox('success', $LNG['password_changed']);
                } elseif ($_GET['m'] == 'i') {
                    $TMPL['message'] = notificationBox('info', $LNG['password_not_changed']);
                }
            } elseif ($_GET['b'] == 'social') {
                // Security Admin Tab
                $skin = new skin('admin/social');
                $page = '';
                if (!extension_loaded('openssl')) {
                    $TMPL['message'] .= notificationBox('error', $LNG['openssl_error']);
                }
                if (!function_exists('curl_exec')) {
                    $TMPL['message'] .= notificationBox('info', $LNG['curl_error']);
                }
                $TMPL['fbappid'] = $settings['fbappid'];
                $TMPL['fbappsecret'] = $settings['fbappsecret'];
                if (empty($settings['fbapp'])) {
                    $TMPL['fbappoff'] = ' selected="selected"';
                } else {
                    $TMPL['fbappon'] = ' selected="selected"';
                }
                if (!empty($_POST)) {
                    $updateSettings = new updateSettings();
                    $updateSettings->db = $db;
                    $updated = $updateSettings->query_array('settings', $_POST);
                    if ($updated == 1) {
                        header("Location: " . $CONF['url'] . "/index.php?a=admin&b=social&m=s");
                    } else {
                        header("Location: " . $CONF['url'] . "/index.php?a=admin&b=social&m=i");
                    }
                }
                if ($_GET['m'] == 's') {
                    $TMPL['message'] .= notificationBox('success', $LNG['settings_saved']);
                } elseif ($_GET['m'] == 'i') {
                    $TMPL['message'] .= notificationBox('info', $LNG['nothing_changed']);
                }
            } elseif ($_GET['b'] == 'payments') {
                $managePayments = new managePayments();
                $managePayments->db = $db;
                $managePayments->url = $CONF['url'];
                $managePayments->per_page = $settings['rperpage'];
                if (isset($_GET['id'])) {
                    $skin = new skin('admin/payment');
                    $page = '';
                    if (isset($_GET['type'])) {
                        $managePayments->updatePayment($_GET['id'], $_GET['type']);
                    }
                    $TMPL['content'] = $managePayments->getPayment($_GET['id']);
                    // If the payment doens't exist
                    if (empty($TMPL['content'])) {
                        header("Location: " . $CONF['url'] . "/index.php?a=admin&b=payments&m=i");
                    }
                } else {
                    $skin = new skin('admin/manage_payments');
                    $page = '';
                    $TMPL['payments'] = $managePayments->getPayments(0);
                }
                if ($_GET['m'] == 'i') {
                    $TMPL['message'] = notificationBox('error', $LNG['payment_not_exist']);
                }
            } elseif ($_GET['b'] == 'pro') {
                // Security Admin Tab
                $skin = new skin('admin/pro');
                $page = '';
                if (!extension_loaded('openssl')) {
                    $TMPL['message'] .= notificationBox('error', $LNG['openssl_error']);
                }
                if (!function_exists('curl_exec')) {
                    $TMPL['message'] .= notificationBox('info', $LNG['curl_error']);
                }
                $TMPL['ppuser'] = $settings['paypaluser'];
                $TMPL['pppass'] = $settings['paypalpass'];
                $TMPL['ppsign'] = $settings['paypalsign'];
                $TMPL['currentProMonth'] = $settings['promonth'];
                $TMPL['currentProYear'] = $settings['proyear'];
                if (empty($settings['paypalapp'])) {
                    $TMPL['ppappoff'] = ' selected="selected"';
                } else {
                    $TMPL['ppappon'] = ' selected="selected"';
                }
                if (empty($settings['paypalsand'])) {
                    $TMPL['ppsandoff'] = ' selected="selected"';
                } else {
                    $TMPL['ppsandon'] = ' selected="selected"';
                }
                if ($settings['protracksize'] == '5242880') {
                    $TMPL['aprotrack'] = 'selected="selected"';
                } elseif ($settings['protracksize'] == '10485760') {
                    $TMPL['bprotrack'] = 'selected="selected"';
                } elseif ($settings['protracksize'] == '26214400') {
                    $TMPL['cprotrack'] = 'selected="selected"';
                } elseif ($settings['protracksize'] == '52428800') {
                    $TMPL['dprotrack'] = 'selected="selected"';
                } elseif ($settings['protracksize'] == '104857600') {
                    $TMPL['eprotrack'] = 'selected="selected"';
                } elseif ($settings['protracksize'] == '262144000') {
                    $TMPL['fprotrack'] = 'selected="selected"';
                } elseif ($settings['protracksize'] == '524288000') {
                    $TMPL['gprotrack'] = 'selected="selected"';
                } elseif ($settings['protracksize'] == '1073741824') {
                    $TMPL['hprotrack'] = 'selected="selected"';
                } else {
                    $TMPL['iprotrack'] = 'selected="selected"';
                }
                if ($settings['protracktotal'] == '104857600') {
                    $TMPL['aprototal'] = 'selected="selected"';
                } elseif ($settings['protracktotal'] == '209715200') {
                    $TMPL['bprototal'] = 'selected="selected"';
                } elseif ($settings['protracktotal'] == '314572800') {
                    $TMPL['cprototal'] = 'selected="selected"';
                } elseif ($settings['protracktotal'] == '524288000') {
                    $TMPL['dprototal'] = 'selected="selected"';
                } elseif ($settings['protracktotal'] == '1073741824') {
                    $TMPL['eprototal'] = 'selected="selected"';
                } elseif ($settings['protracktotal'] == '5368709120') {
                    $TMPL['fprototal'] = 'selected="selected"';
                } elseif ($settings['protracktotal'] == '10737418240') {
                    $TMPL['gprototal'] = 'selected="selected"';
                } elseif ($settings['protracktotal'] == '26843545600') {
                    $TMPL['hprototal'] = 'selected="selected"';
                } else {
                    $TMPL['iprototal'] = 'selected="selected"';
                }
                if ($settings['tracksize'] == '5242880') {
                    $TMPL['atrack'] = 'selected="selected"';
                } elseif ($settings['tracksize'] == '10485760') {
                    $TMPL['btrack'] = 'selected="selected"';
                } elseif ($settings['tracksize'] == '26214400') {
                    $TMPL['ctrack'] = 'selected="selected"';
                } elseif ($settings['tracksize'] == '52428800') {
                    $TMPL['dtrack'] = 'selected="selected"';
                } else {
                    $TMPL['etrack'] = 'selected="selected"';
                }
                if ($settings['currency'] == 'USD') {
                    $TMPL['usd_currency'] = 'selected="selected"';
                } elseif ($settings['currency'] == 'EUR') {
                    $TMPL['eur_currency'] = 'selected="selected"';
                } else {
                    $TMPL['gbp_currency'] = 'selected="selected"';
                }
                if ($settings['tracksizetotal'] == '104857600') {
                    $TMPL['atotal'] = 'selected="selected"';
                } elseif ($settings['tracksizetotal'] == '209715200') {
                    $TMPL['btotal'] = 'selected="selected"';
                } elseif ($settings['tracksizetotal'] == '314572800') {
                    $TMPL['ctotal'] = 'selected="selected"';
                } elseif ($settings['tracksizetotal'] == '524288000') {
                    $TMPL['dtotal'] = 'selected="selected"';
                } else {
                    $TMPL['etotal'] = 'selected="selected"';
                }
                if (!empty($_POST)) {
                    $updateSettings = new updateSettings();
                    $updateSettings->db = $db;
                    $updated = $updateSettings->query_array('settings', $_POST);
                    if ($updated == 1) {
                        header("Location: " . $CONF['url'] . "/index.php?a=admin&b=pro&m=s");
                    } else {
                        header("Location: " . $CONF['url'] . "/index.php?a=admin&b=pro&m=i");
                    }
                }
                if ($_GET['m'] == 's') {
                    $TMPL['message'] .= notificationBox('success', $LNG['settings_saved']);
                } elseif ($_GET['m'] == 'i') {
                    $TMPL['message'] .= notificationBox('info', $LNG['nothing_changed']);
                }
            } elseif ($_GET['b'] == 'stats') {
                // Security Admin Tab
                $skin = new skin('admin/stats');
                $page = '';
                list($TMPL['tracks_total'], $TMPL['tracks_public'], $TMPL['tracks_private'], $TMPL['comments_total'], $TMPL['users_today'], $TMPL['users_this_month'], $TMPL['users_last_30'], $TMPL['users_total'], $TMPL['total_reports'], $TMPL['pending_reports'], $TMPL['safe_reports'], $TMPL['deleted_reports'], $TMPL['total_tracks_reports'], $TMPL['pending_track_reports'], $TMPL['safe_track_reports'], $TMPL['deleted_track_reports'], $TMPL['total_comment_reports'], $TMPL['pending_comment_reports'], $TMPL['safe_comment_reports'], $TMPL['deleted_comment_reports'], $TMPL['total_likes'], $TMPL['likes_today'], $TMPL['likes_this_month'], $TMPL['likes_last_30'], $TMPL['total_plays'], $TMPL['plays_today'], $TMPL['plays_this_month'], $TMPL['plays_last_30'], $TMPL['total_downloads'], $TMPL['downloads_today'], $TMPL['downloads_this_month'], $TMPL['downloads_last_30'], $TMPL['total_playlists'], $TMPL['playlists_today'], $TMPL['playlists_this_month'], $TMPL['playlists_last_30'], $TMPL['total_payments'], $TMPL['payments_today'], $TMPL['payments_this_month'], $TMPL['payments_last_30'], $TMPL['total_earnings'], $TMPL['earnings_today'], $TMPL['earnings_this_month'], $TMPL['earnings_last_30']) = statistics($db, $settings['currency']);
                $TMPL['currency'] = $settings['currency'];
            } elseif ($_GET['b'] == 'themes') {
                $skin = new skin('admin/themes');
                $page = '';
                $updateSettings = new updateSettings();
                $updateSettings->db = $db;
                $themes = $updateSettings->getThemes();
                $TMPL['themes_list'] = $themes[0];
                if (isset($_GET['theme'])) {
                    // If theme is in array
                    if (in_array($_GET['theme'], $themes[1])) {
                        $updated = $updateSettings->query_array('settings', array('theme' => $_GET['theme']));
                        if ($updated == 1) {
                            header("Location: " . $CONF['url'] . "/index.php?a=admin&b=themes&m=s");
                        } else {
                            header("Location: " . $CONF['url'] . "/index.php?a=admin&b=themes&m=i");
                        }
                    }
                }
                if ($_GET['m'] == 's') {
                    $TMPL['message'] = notificationBox('success', $LNG['theme_changed']);
                } elseif ($_GET['m'] == 'i') {
                    $TMPL['message'] = notificationBox('error', $LNG['nothing_changed']);
                }
            } elseif ($_GET['b'] == 'reports') {
                $manageReports = new manageReports();
                $manageReports->db = $db;
                $manageReports->url = $CONF['url'];
                $manageReports->title = $settings['title'];
                $manageReports->per_page = $settings['rperpage'];
                if (ctype_digit($_GET['id'])) {
                    if (isset($_GET['type'])) {
                        // Do the manage report action
                        $manageReport = $manageReports->manageReport($_GET['id'], $_GET['type']);
                    }
                    $skin = new skin('admin/report');
                    $page = '';
                    $TMPL['content'] = $manageReports->getReport($_GET['id']);
                    // If the report doesn't exist
                    if (empty($TMPL['content'])) {
                        header("Location: " . $CONF['url'] . "/index.php?a=admin&b=reports&m=i");
                    }
                } else {
                    $skin = new skin('admin/manage_reports');
                    $page = '';
                    $TMPL['reports'] = $manageReports->getReports(0);
                }
                if ($_GET['m'] == 'i') {
                    $TMPL['message'] = notificationBox('error', $LNG['report_not_exist']);
                }
            } elseif ($_GET['b'] == 'users_settings') {
                $skin = new skin('admin/users_settings');
                $page = '';
                if ($settings['notificationl'] == '0') {
                    $TMPL['loff'] = 'selected="selected"';
                } else {
                    $TMPL['lon'] = 'selected="selected"';
                }
                if ($settings['notificationc'] == '0') {
                    $TMPL['coff'] = 'selected="selected"';
                } else {
                    $TMPL['con'] = 'selected="selected"';
                }
                if ($settings['email_comment'] == '0') {
                    $TMPL['ecoff'] = 'selected="selected"';
                } else {
                    $TMPL['econ'] = 'selected="selected"';
                }
                if ($settings['email_like'] == '0') {
                    $TMPL['eloff'] = 'selected="selected"';
                } else {
                    $TMPL['elon'] = 'selected="selected"';
                }
                if ($settings['email_new_friend'] == '0') {
                    $TMPL['enfoff'] = 'selected="selected"';
                } else {
                    $TMPL['enfon'] = 'selected="selected"';
                }
                if ($settings['notificationd'] == '0') {
                    $TMPL['doff'] = 'selected="selected"';
                } else {
                    $TMPL['don'] = 'selected="selected"';
                }
                if ($settings['notificationf'] == '0') {
                    $TMPL['foff'] = 'selected="selected"';
                } else {
                    $TMPL['fon'] = 'selected="selected"';
                }
                if ($settings['ronline'] == '3') {
                    $TMPL['uone'] = 'selected="selected"';
                } elseif ($settings['ronline'] == '7') {
                    $TMPL['utwo'] = 'selected="selected"';
                } else {
                    $TMPL['uthree'] = 'selected="selected"';
                }
                if ($settings['nperwidget'] == '5') {
                    $TMPL['none'] = 'selected="selected"';
                } elseif ($settings['nperwidget'] == '10') {
                    $TMPL['ntwo'] = 'selected="selected"';
                } elseif ($settings['nperwidget'] == '20') {
                    $TMPL['nthree'] = 'selected="selected"';
                } else {
                    $TMPL['nfour'] = 'selected="selected"';
                }
                if ($settings['lperpost'] == '5') {
                    $TMPL['likeson'] = 'selected="selected"';
                } else {
                    $TMPL['likesoff'] = 'selected="selected"';
                }
                if (!empty($_POST)) {
                    $updateSettings = new updateSettings();
                    $updateSettings->db = $db;
                    $updated = $updateSettings->query_array('settings', $_POST);
                    if ($updated == 1) {
                        header("Location: " . $CONF['url'] . "/index.php?a=admin&b=users_settings&m=s");
                    } else {
                        header("Location: " . $CONF['url'] . "/index.php?a=admin&b=users_settings&m=i");
                    }
                }
                if ($_GET['m'] == 's') {
                    $TMPL['message'] = notificationBox('success', $LNG['settings_saved']);
                } elseif ($_GET['m'] == 'i') {
                    $TMPL['message'] = notificationBox('info', $LNG['nothing_changed']);
                }
            } elseif ($_GET['b'] == 'users') {
                $manageUsers = new manageUsers();
                $manageUsers->db = $db;
                $manageUsers->url = $CONF['url'];
                $manageUsers->title = $settings['title'];
                $manageUsers->per_page = $settings['rperpage'];
                if (!isset($_GET['id']) && !isset($_GET['idu'])) {
                    $skin = new skin('admin/manage_users');
                    $page = '';
                    // Save the array returned into a list
                    $TMPL['users'] = $manageUsers->getUsers(0);
                } else {
                    $skin = new skin('admin/user');
                    $page = '';
                    $getUser = $manageUsers->getUser($_GET['id'], $_GET['idu']);
                    if (!$getUser) {
                        header("Location: " . $CONF['url'] . "/index.php?a=admin&b=users&m=un");
                    }
                    // Create the class instance
                    $updateUserSettings = new updateUserSettings();
                    $updateUserSettings->db = $db;
                    $updateUserSettings->id = $getUser['idu'];
                    if (!empty($_POST)) {
                        $TMPL['message'] = $updateUserSettings->query_array('users', array_map("strip_tags_array", $_POST));
                    }
                    $userSettings = $updateUserSettings->getSettings();
                    $TMPL['countries'] = countries(1, $userSettings['country']);
                    $TMPL['username'] = $userSettings['username'];
                    $TMPL['idu'] = $userSettings['idu'];
                    $TMPL['currentFirstName'] = $userSettings['first_name'];
                    $TMPL['currentLastName'] = $userSettings['last_name'];
                    $TMPL['currentEmail'] = $userSettings['email'];
                    $TMPL['currentCity'] = $userSettings['city'];
                    $TMPL['currentWebsite'] = $userSettings['website'];
                    $TMPL['currentDescription'] = $userSettings['description'];
                    $TMPL['currentFacebook'] = $userSettings['facebook'];
                    $TMPL['currentTwitter'] = $userSettings['twitter'];
                    $TMPL['currentGplus'] = $userSettings['gplus'];
                    $TMPL['currentYouTube'] = $userSettings['youtube'];
                    $TMPL['currentSoundCloud'] = $userSettings['soundcloud'];
                    $TMPL['currentLastfm'] = $userSettings['lastfm'];
                    $TMPL['currentMySpace'] = $userSettings['myspace'];
                    $TMPL['currentVimeo'] = $userSettings['vimeo'];
                    $TMPL['currentTumblr'] = $userSettings['tumblr'];
                    $feed = new feed();
                    $feed->db = $db;
                    $feed->id = $updateUserSettings->id;
                    $manageReports = new manageReports();
                    $manageReports->db = $db;
                    $manageReports->url = $CONF['url'];
                    $manageReports->per_page = $settings['rperpage'];
                    if (isset($_GET['suspend'])) {
                        $manageUsers->suspendUser($feed->id, $_GET['suspend']);
                    }
                    $user = $manageUsers->getUser($getUser['idu']);
                    $TMPL['username'] = '******' . $CONF['url'] . '/index.php?a=profile&u=' . $user['username'] . '" target="_blank"><img src="' . $CONF['url'] . '/thumb.php?src=' . $user['image'] . '&t=a&w=112&h=112"></a></div>
											<div class="manage-users-content"><a href="' . $CONF['url'] . '/index.php?a=profile&u=' . $user['username'] . '" target="_blank">' . $user['username'] . '</a><br>' . $user['email'] . '</div>';
                    $TMPL['reports'] = $manageReports->getReports(0, $feed->getTrackList($feed->id) ? $feed->getTrackList($feed->id) : 1);
                    if (empty($TMPL['reports'])) {
                        $TMPL['hide_r'] = ' style="display: none;"';
                    }
                    // If the user has payments history
                    $managePayments = new managePayments();
                    $managePayments->db = $db;
                    $managePayments->url = $CONF['url'];
                    $managePayments->per_page = $settings['rperpage'];
                    $TMPL['history'] = $managePayments->getPayments(0, $updateUserSettings->id);
                    if (empty($TMPL['history'])) {
                        $TMPL['hide_p'] = ' style="display: none;"';
                    }
                    // Suspend variable for the suspend url
                    $TMPL['suspend'] = $user['suspended'] ? '0' : '1';
                    $TMPL['status_desc'] = $user['suspended'] ? $LNG['restore_account'] : $LNG['suspend_account'];
                    $TMPL['status'] = $user['suspended'] ? notificationBox('error', $LNG['account_suspended']) : '';
                    if ($user['suspended']) {
                        $TMPL['suspended'] = $LNG['restore'];
                    } else {
                        $TMPL['suspended'] = $LNG['suspend'];
                    }
                }
                // If GET delete is set, delete the user
                if ($_GET['delete']) {
                    $manageUsers->deleteUser($_GET['delete']);
                    header("Location: " . $CONF['url'] . "/index.php?a=admin&b=users&m=" . $_GET['delete']);
                }
                if ($_GET['m'] == 'un') {
                    $TMPL['message'] = notificationBox('error', $LNG['user_not_exist']);
                } elseif (!empty($_GET['m'])) {
                    $TMPL['message'] = notificationBox('success', sprintf($LNG['user_has_been_deleted'], $_GET['m']));
                }
            } elseif ($_GET['b'] == 'categories') {
                $manageCategories = new manageCategories();
                $manageCategories->db = $db;
                $manageCategories->url = $CONF['url'];
                $skin = new skin('admin/manage_categories');
                $page = '';
                $TMPL['categories'] = $manageCategories->getCategories();
            } elseif ($_GET['b'] == 'ads') {
                $skin = new skin('admin/manage_ads');
                $page = '';
                $TMPL['ad1'] = $settings['ad1'];
                $TMPL['ad2'] = $settings['ad2'];
                $TMPL['ad3'] = $settings['ad3'];
                $TMPL['ad4'] = $settings['ad4'];
                $TMPL['ad5'] = $settings['ad5'];
                $TMPL['ad6'] = $settings['ad6'];
                $TMPL['ad7'] = $settings['ad7'];
                if (!empty($_POST)) {
                    // Unset the submit array element
                    $updateSettings = new updateSettings();
                    $updateSettings->db = $db;
                    $updated = $updateSettings->query_array('settings', $_POST);
                    if ($updated == 1) {
                        header("Location: " . $CONF['url'] . "/index.php?a=admin&b=ads&m=s");
                    } else {
                        header("Location: " . $CONF['url'] . "/index.php?a=admin&b=ads&m=i");
                    }
                }
                if ($_GET['m'] == 's') {
                    $TMPL['message'] = notificationBox('success', $LNG['settings_saved']);
                } elseif ($_GET['m'] == 'i') {
                    $TMPL['message'] = notificationBox('info', $LNG['nothing_changed']);
                }
            } else {
                $skin = new skin('admin/general');
                $page = '';
                $TMPL['currentTitle'] = $settings['title'];
                $TMPL['currentFormat'] = $settings['format'];
                $TMPL['currentArtFormat'] = $settings['artformat'];
                $TMPL['currentTrackFormat'] = $settings['trackformat'];
                if ($settings['captcha'] == '1') {
                    $TMPL['on'] = 'selected="selected"';
                } else {
                    $TMPL['off'] = 'selected="selected"';
                }
                if ($settings['time'] == '0') {
                    $TMPL['one'] = 'selected="selected"';
                } elseif ($settings['time'] == '1') {
                    $TMPL['two'] = 'selected="selected"';
                } elseif ($settings['time'] == '2') {
                    $TMPL['three'] = 'selected="selected"';
                } else {
                    $TMPL['four'] = 'selected="selected"';
                }
                if ($settings['volume'] == '0.20') {
                    $TMPL['vtwenty'] = 'selected="selected"';
                } elseif ($settings['volume'] == '0.40') {
                    $TMPL['vfourty'] = 'selected="selected"';
                } elseif ($settings['volume'] == '0.60') {
                    $TMPL['vsixty'] = 'selected="selected"';
                } elseif ($settings['volume'] == '0.80') {
                    $TMPL['veighty'] = 'selected="selected"';
                } elseif ($settings['volume'] == '1') {
                    $TMPL['vhundred'] = 'selected="selected"';
                }
                if ($settings['conline'] == '60') {
                    $TMPL['conone'] = 'selected="selected"';
                } elseif ($settings['conline'] == '300') {
                    $TMPL['contwo'] = 'selected="selected"';
                } else {
                    $TMPL['conthree'] = 'selected="selected"';
                }
                if ($settings['perpage'] == '10') {
                    $TMPL['ten'] = 'selected="selected"';
                } elseif ($settings['perpage'] == '20') {
                    $TMPL['twenty'] = 'selected="selected"';
                } elseif ($settings['perpage'] == '35') {
                    $TMPL['thirtyfive'] = 'selected="selected"';
                } else {
                    $TMPL['fifty'] = 'selected="selected"';
                }
                if ($settings['nperpage'] == '10') {
                    $TMPL['nten'] = 'selected="selected"';
                } elseif ($settings['nperpage'] == '25') {
                    $TMPL['ntwentyfive'] = 'selected="selected"';
                } elseif ($settings['nperpage'] == '50') {
                    $TMPL['nfifty'] = 'selected="selected"';
                } else {
                    $TMPL['nonehundred'] = 'selected="selected"';
                }
                if ($settings['mperpage'] == '5') {
                    $TMPL['mone'] = 'selected="selected"';
                } elseif ($settings['mperpage'] == '10') {
                    $TMPL['mtwo'] = 'selected="selected"';
                } elseif ($settings['mperpage'] == '25') {
                    $TMPL['mthree'] = 'selected="selected"';
                } else {
                    $TMPL['mfour'] = 'selected="selected"';
                }
                if ($settings['mlimit'] == '500') {
                    $TMPL['cone'] = 'selected="selected"';
                } elseif ($settings['mlimit'] == '1000') {
                    $TMPL['ctwo'] = 'selected="selected"';
                } elseif ($settings['mlimit'] == '2500') {
                    $TMPL['cthree'] = 'selected="selected"';
                } else {
                    $TMPL['cfour'] = 'selected="selected"';
                }
                if ($settings['chatr'] == '1') {
                    $TMPL['crone'] = 'selected="selected"';
                } elseif ($settings['chatr'] == '2') {
                    $TMPL['crtwo'] = 'selected="selected"';
                } elseif ($settings['chatr'] == '3') {
                    $TMPL['crthree'] = 'selected="selected"';
                } elseif ($settings['chatr'] == '5') {
                    $TMPL['crfive'] = 'selected="selected"';
                } elseif ($settings['chatr'] == '10') {
                    $TMPL['crten'] = 'selected="selected"';
                } elseif ($settings['chatr'] == '30') {
                    $TMPL['crthirty'] = 'selected="selected"';
                } else {
                    $TMPL['croff'] = 'selected="selected"';
                }
                if ($settings['qperpage'] == '10') {
                    $TMPL['qten'] = 'selected="selected"';
                } elseif ($settings['qperpage'] == '20') {
                    $TMPL['qtwenty'] = 'selected="selected"';
                } elseif ($settings['qperpage'] == '35') {
                    $TMPL['qthirtyfive'] = 'selected="selected"';
                } else {
                    $TMPL['qfifty'] = 'selected="selected"';
                }
                if ($settings['cperpage'] == '5') {
                    $TMPL['cfive'] = 'selected="selected"';
                } elseif ($settings['cperpage'] == '10') {
                    $TMPL['cten'] = 'selected="selected"';
                } elseif ($settings['cperpage'] == '25') {
                    $TMPL['ctwentyfive'] = 'selected="selected"';
                } else {
                    $TMPL['cfifty'] = 'selected="selected"';
                }
                if ($settings['size'] == '1048576') {
                    $TMPL['onemb'] = 'selected="selected"';
                } elseif ($settings['size'] == '2097152') {
                    $TMPL['twomb'] = 'selected="selected"';
                } elseif ($settings['size'] == '3145728') {
                    $TMPL['threemb'] = 'selected="selected"';
                } else {
                    $TMPL['tenmb'] = 'selected="selected"';
                }
                if ($settings['mail'] == '1') {
                    $TMPL['mailon'] = 'selected="selected"';
                } else {
                    $TMPL['mailoff'] = 'selected="selected"';
                }
                if ($settings['intervaln'] == '10000') {
                    $TMPL['intonen'] = 'selected="selected"';
                } elseif ($settings['intervaln'] == '30000') {
                    $TMPL['inttwon'] = 'selected="selected"';
                } elseif ($settings['intervaln'] == '60000') {
                    $TMPL['intthreen'] = 'selected="selected"';
                } elseif ($settings['intervaln'] == '120000') {
                    $TMPL['intfourn'] = 'selected="selected"';
                } elseif ($settings['intervaln'] == '300000') {
                    $TMPL['intfiven'] = 'selected="selected"';
                } elseif ($settings['intervaln'] == '600000') {
                    $TMPL['intsixn'] = 'selected="selected"';
                } else {
                    $TMPL['intsevenn'] = 'selected="selected"';
                }
                if ($settings['artsize'] == '1048576') {
                    $TMPL['aart'] = 'selected="selected"';
                } elseif ($settings['artsize'] == '2097152') {
                    $TMPL['bart'] = 'selected="selected"';
                } elseif ($settings['artsize'] == '3145728') {
                    $TMPL['cart'] = 'selected="selected"';
                } else {
                    $TMPL['dart'] = 'selected="selected"';
                }
                if ($settings['rperpage'] == '10') {
                    $TMPL['rpone'] = 'selected="selected"';
                } elseif ($settings['rperpage'] == '20') {
                    $TMPL['rptwo'] = 'selected="selected"';
                } elseif ($settings['rperpage'] == '50') {
                    $TMPL['rpthree'] = 'selected="selected"';
                } else {
                    $TMPL['rpfour'] = 'selected="selected"';
                }
                if ($settings['sperpage'] == '10') {
                    $TMPL['sone'] = 'selected="selected"';
                } elseif ($settings['sperpage'] == '20') {
                    $TMPL['stwo'] = 'selected="selected"';
                } elseif ($settings['sperpage'] == '35') {
                    $TMPL['sthree'] = 'selected="selected"';
                } else {
                    $TMPL['sfour'] = 'selected="selected"';
                }
                if ($settings['aperip'] == '1') {
                    $TMPL['ipone'] = 'selected="selected"';
                } elseif ($settings['aperip'] == '3') {
                    $TMPL['iptwo'] = 'selected="selected"';
                } elseif ($settings['aperip'] == '5') {
                    $TMPL['ipthree'] = 'selected="selected"';
                } elseif ($settings['aperip'] == '10') {
                    $TMPL['ipfour'] = 'selected="selected"';
                } else {
                    $TMPL['ipoff'] = 'selected="selected"';
                }
                if (isset($_POST['submit'])) {
                    // Unset the submit array element
                    unset($_POST['submit']);
                    $updateSettings = new updateSettings();
                    $updateSettings->db = $db;
                    $updated = $updateSettings->query_array('settings', $_POST);
                    if ($updated == 1) {
                        header("Location: " . $CONF['url'] . "/index.php?a=admin&m=s");
                    } else {
                        header("Location: " . $CONF['url'] . "/index.php?a=admin&m=i");
                    }
                }
                if ($_GET['m'] == 's') {
                    $TMPL['message'] = notificationBox('success', $LNG['settings_saved']);
                } elseif ($_GET['m'] == 'i') {
                    $TMPL['message'] = notificationBox('info', $LNG['nothing_changed']);
                }
            }
            $page .= $skin->make();
            $TMPL = $TMPL_old;
            unset($TMPL_old);
            $TMPL['settings'] = $page;
            if (isset($_GET['logout']) == 1) {
                $loggedInAdmin->logOut();
                header("Location: " . $CONF['url'] . "/index.php?a=admin");
            }
        } else {
            // Set the content to false, change the $skin to log-in.
            $content = false;
        }
    }
    // Bold the current link
    if (isset($_GET['b'])) {
        $LNG["admin_menu_{$_GET['b']}"] = $LNG["admin_menu_{$_GET['b']}"];
        $TMPL['welcome'] = $LNG["admin_ttl_{$_GET['b']}"];
    } else {
        $LNG["admin_menu_general"] = $LNG["admin_menu_general"];
        $TMPL['welcome'] = $LNG["admin_ttl_general"];
    }
    function adminMenuCounts($db, $type)
    {
        // Type 0: Return the reports number
        if ($type == 0) {
            $query = $db->query('SELECT COUNT(`id`) as `count` FROM `reports` WHERE `state` = 0');
        }
        $result = $query->fetch_assoc();
        return $result['count'];
    }
    $adminMenu = array('' => array('admin_menu_general', ''), '&b=users_settings' => array('admin_menu_users_settings', ''), '&b=pro' => array('admin_menu_pro', ''), '&b=social' => array('admin_menu_social', ''), '&b=themes' => array('admin_menu_themes', ''), '&b=stats' => array('admin_menu_stats', ''), '&b=security' => array('admin_menu_security', ''), '&b=users' => array('admin_menu_manage_users', ''), '&b=payments' => array('admin_menu_manage_payments', ''), '&b=reports' => array('admin_menu_manage_reports', adminMenuCounts($db, 0)), '&b=categories' => array('admin_menu_manage_categories', ''), '&b=ads' => array('admin_menu_manage_ads', ''), '&logout=1' => array('admin_menu_logout', ''));
    foreach ($adminMenu as $link => $title) {
        if ($link == '&b=' . $_GET['b'] || $link == $_GET['b']) {
            $TMPL['admin_menu'] .= '<strong>';
            $ttl = $LNG[$title[0]];
        }
        $TMPL['admin_menu'] .= '<a href="' . $CONF['url'] . '/index.php?a=admin' . $link . '" ' . ($title[0] == 'admin_menu_logout' ? '' : 'rel="loadpage"') . '>' . $LNG[$title[0]] . ' ' . ($title[1] ? '<span class="admin-notifications-number">' . $title[1] . '</span>' : '') . '</a>';
        if ($link == '&b=' . $_GET['b'] || $link == $_GET['b']) {
            $TMPL['admin_menu'] .= '</strong>';
        }
    }
    $TMPL['url'] = $CONF['url'];
    $TMPL['title'] = $LNG['title_admin'] . ' - ' . ($loggedIn['username'] ? $ttl : $LNG['login']) . ' - ' . $settings['title'];
    if ($content) {
        $skin = new skin('admin/content');
    } else {
        $skin = new skin('admin/login');
    }
    return $skin->make();
}
Beispiel #8
0
function PageMain()
{
    global $TMPL, $LNG, $CONF, $db, $settings;
    if (isset($_POST['login'])) {
        $logInAdmin = new logInAdmin();
        $logInAdmin->db = $db;
        $logInAdmin->url = $CONF['url'];
        $logInAdmin->username = $_POST['username'];
        $logInAdmin->password = $_POST['password'];
        $TMPL['message'] = $logInAdmin->in();
    }
    if (isset($_SESSION['usernameAdmin']) && isset($_SESSION['passwordAdmin'])) {
        $loggedInAdmin = new loggedInAdmin();
        $loggedInAdmin->db = $db;
        $loggedInAdmin->url = $CONF['url'];
        $loggedInAdmin->username = $_SESSION['usernameAdmin'];
        $loggedInAdmin->password = $_SESSION['passwordAdmin'];
        $loggedIn = $loggedInAdmin->verify();
        if ($loggedIn['username']) {
            // Set the content to true, change the $skin to content
            $content = true;
            $TMPL_old = $TMPL;
            $TMPL = array();
            $TMPL['url'] = $CONF['url'];
            if ($_GET['b'] == 'security') {
                // Security Admin Tab
                $skin = new skin('admin/security');
                $page = '';
                if (!empty($_POST)) {
                    $updateSettings = new updateSettings();
                    $updateSettings->db = $db;
                    $updated = $updateSettings->query_array('admin', $_POST);
                    if ($updated == 1) {
                        header("Location: " . $CONF['url'] . "/index.php?a=admin&b=security&m=s");
                    } else {
                        header("Location: " . $CONF['url'] . "/index.php?a=admin&b=security&m=i");
                    }
                }
                if ($_GET['m'] == 's') {
                    $TMPL['message'] = notificationBox('success', $LNG['password_changed'], $LNG['password_success_changed']);
                } elseif ($_GET['m'] == 'i') {
                    $TMPL['message'] = notificationBox('info', $LNG['nothing_changed'], $LNG['password_not_changed']);
                }
            } elseif ($_GET['b'] == 'stats') {
                // Security Admin Tab
                $skin = new skin('admin/stats');
                $page = '';
                list($TMPL['messages_total'], $TMPL['messages_public'], $TMPL['messages_private'], $TMPL['comments_total'], $TMPL['users_today'], $TMPL['users_this_month'], $TMPL['users_last_30'], $TMPL['users_total'], $TMPL['total_reports'], $TMPL['pending_reports'], $TMPL['safe_reports'], $TMPL['deleted_reports'], $TMPL['total_message_reports'], $TMPL['pending_message_reports'], $TMPL['safe_message_reports'], $TMPL['deleted_message_reports'], $TMPL['total_comment_reports'], $TMPL['pending_comment_reports'], $TMPL['safe_comment_reports'], $TMPL['deleted_comment_reports'], $TMPL['total_likes'], $TMPL['likes_today'], $TMPL['likes_this_month'], $TMPL['likes_last_30']) = users_stats($db);
            } elseif ($_GET['b'] == 'manage_reports') {
                $skin = new skin('admin/manage_reports');
                $page = '';
                $manageReports = new manageReports();
                $manageReports->db = $db;
                $manageReports->url = $CONF['url'];
                $manageReports->per_page = $settings['rperpage'];
                // Save the array returned into a list
                $TMPL['reports'] = $manageReports->getReports(0);
            } elseif ($_GET['b'] == 'users_settings') {
                $skin = new skin('admin/users_settings');
                $page = '';
                if ($settings['mprivacy'] == '1') {
                    $TMPL['pon'] = 'selected="selected"';
                } else {
                    $TMPL['poff'] = 'selected="selected"';
                }
                if ($settings['notificationl'] == '0') {
                    $TMPL['loff'] = 'selected="selected"';
                } else {
                    $TMPL['lon'] = 'selected="selected"';
                }
                if ($settings['notificationc'] == '0') {
                    $TMPL['coff'] = 'selected="selected"';
                } else {
                    $TMPL['con'] = 'selected="selected"';
                }
                if ($settings['sound_new_notification'] == '0') {
                    $TMPL['snnoff'] = 'selected="selected"';
                } else {
                    $TMPL['snnon'] = 'selected="selected"';
                }
                if ($settings['sound_new_chat'] == '0') {
                    $TMPL['sncoff'] = 'selected="selected"';
                } else {
                    $TMPL['sncon'] = 'selected="selected"';
                }
                if ($settings['email_comment'] == '0') {
                    $TMPL['ecoff'] = 'selected="selected"';
                } else {
                    $TMPL['econ'] = 'selected="selected"';
                }
                if ($settings['email_like'] == '0') {
                    $TMPL['eloff'] = 'selected="selected"';
                } else {
                    $TMPL['elon'] = 'selected="selected"';
                }
                if ($settings['email_new_friend'] == '0') {
                    $TMPL['enfoff'] = 'selected="selected"';
                } else {
                    $TMPL['enfon'] = 'selected="selected"';
                }
                if ($settings['notifications'] == '0') {
                    $TMPL['soff'] = 'selected="selected"';
                } else {
                    $TMPL['son'] = 'selected="selected"';
                }
                if ($settings['notificationd'] == '0') {
                    $TMPL['doff'] = 'selected="selected"';
                } else {
                    $TMPL['don'] = 'selected="selected"';
                }
                if ($settings['notificationf'] == '0') {
                    $TMPL['foff'] = 'selected="selected"';
                } else {
                    $TMPL['fon'] = 'selected="selected"';
                }
                if ($settings['ilimit'] == '1') {
                    $TMPL['ione'] = 'selected="selected"';
                } elseif ($settings['ilimit'] == '3') {
                    $TMPL['ithree'] = 'selected="selected"';
                } elseif ($settings['ilimit'] == '6') {
                    $TMPL['isix'] = 'selected="selected"';
                } else {
                    $TMPL['inine'] = 'selected="selected"';
                }
                if ($settings['ronline'] == '5') {
                    $TMPL['uone'] = 'selected="selected"';
                } elseif ($settings['ronline'] == '10') {
                    $TMPL['utwo'] = 'selected="selected"';
                } else {
                    $TMPL['uthree'] = 'selected="selected"';
                }
                if ($settings['nperwidget'] == '5') {
                    $TMPL['none'] = 'selected="selected"';
                } elseif ($settings['nperwidget'] == '10') {
                    $TMPL['ntwo'] = 'selected="selected"';
                } elseif ($settings['nperwidget'] == '20') {
                    $TMPL['nthree'] = 'selected="selected"';
                } else {
                    $TMPL['nfour'] = 'selected="selected"';
                }
                if ($settings['lperpost'] == '3') {
                    $TMPL['likesone'] = 'selected="selected"';
                } elseif ($settings['lperpost'] == '5') {
                    $TMPL['likestwo'] = 'selected="selected"';
                } else {
                    $TMPL['likesnone'] = 'selected="selected"';
                }
                if ($settings['verified'] == 0) {
                    $TMPL['off_v'] = 'selected="selected"';
                } else {
                    $TMPL['on_v'] = 'selected="selected"';
                }
                if (!empty($_POST)) {
                    $updateSettings = new updateSettings();
                    $updateSettings->db = $db;
                    $updated = $updateSettings->query_array('settings', $_POST);
                    if ($updated == 1) {
                        header("Location: " . $CONF['url'] . "/index.php?a=admin&b=users_settings&m=s");
                    } else {
                        header("Location: " . $CONF['url'] . "/index.php?a=admin&b=users_settings&m=i");
                    }
                }
                if ($_GET['m'] == 's') {
                    $TMPL['message'] = notificationBox('success', $LNG['settings_saved'], $LNG['general_settings_saved']);
                } elseif ($_GET['m'] == 'i') {
                    $TMPL['message'] = notificationBox('info', $LNG['nothing_saved'], $LNG['general_settings_unaffected']);
                }
            } elseif ($_GET['b'] == 'users') {
                $manageUsers = new manageUsers();
                $manageUsers->db = $db;
                $manageUsers->url = $CONF['url'];
                $manageUsers->per_page = $settings['uperpage'];
                if (!isset($_GET['e'])) {
                    $skin = new skin('admin/manage_users');
                    $page = '';
                    // Save the array returned into a list
                    $TMPL['users'] = $manageUsers->getUsers(0);
                } else {
                    $skin = new skin('admin/edit_users');
                    $page = '';
                    $getUser = $manageUsers->getUser($_GET['e'], $_GET['ef']);
                    if (!$getUser) {
                        header("Location: " . $CONF['url'] . "/index.php?a=admin&b=users&m=un");
                    }
                    // Create the class instance
                    $updateUserSettings = new updateUserSettings();
                    $updateUserSettings->db = $db;
                    $updateUserSettings->id = $getUser['idu'];
                    if (!empty($_POST)) {
                        $TMPL['message'] = $updateUserSettings->query_array('users', array_map("strip_tags_array", $_POST));
                    }
                    $userSettings = $updateUserSettings->getSettings();
                    $date = explode('-', $userSettings['born']);
                    $TMPL['years'] = generateDateForm(0, $date[0]);
                    $TMPL['months'] = generateDateForm(1, $date[1]);
                    $TMPL['days'] = generateDateForm(2, $date[2]);
                    $TMPL['username'] = $userSettings['username'];
                    $TMPL['idu'] = $userSettings['idu'];
                    $TMPL['currentFirstName'] = $userSettings['first_name'];
                    $TMPL['currentLastName'] = $userSettings['last_name'];
                    $TMPL['currentEmail'] = $userSettings['email'];
                    $TMPL['currentLocation'] = $userSettings['location'];
                    $TMPL['currentWebsite'] = $userSettings['website'];
                    $TMPL['currentBio'] = $userSettings['bio'];
                    $TMPL['currentFacebook'] = $userSettings['facebook'];
                    $TMPL['currentTwitter'] = $userSettings['twitter'];
                    $TMPL['currentGplus'] = $userSettings['gplus'];
                    if ($userSettings['verified'] == 0) {
                        $TMPL['off_v'] = 'selected="selected"';
                    } else {
                        $TMPL['on_v'] = 'selected="selected"';
                    }
                }
                // If GET delete is set, delete the user
                if ($_GET['delete']) {
                    $manageUsers->deleteUser($_GET['delete']);
                    header("Location: " . $CONF['url'] . "/index.php?a=admin&b=users&m=" . $_GET['delete']);
                }
                if ($_GET['m'] == 'un') {
                    $TMPL['message'] = notificationBox('error', $LNG['error'], $LNG['user_not_exist']);
                } elseif (!empty($_GET['m'])) {
                    $TMPL['message'] = notificationBox('success', $LNG['user_deleted'], sprintf($LNG['user_has_been_deleted'], $_GET['m']));
                }
            } elseif ($_GET['b'] == 'manage_notices') {
                $skin = new skin('admin/manage_notices');
                $page = '';
                $TMPL['ad1'] = stripslashes($settings['ad1']);
                $TMPL['ad2'] = stripslashes($settings['ad2']);
                $TMPL['ad3'] = stripslashes($settings['ad3']);
                $TMPL['ad4'] = stripslashes($settings['ad4']);
                $TMPL['ad5'] = stripslashes($settings['ad5']);
                $TMPL['ad6'] = stripslashes($settings['ad6']);
                $TMPL['ad7'] = stripslashes($settings['ad7']);
                if (!empty($_POST)) {
                    // Unset the submit array element
                    $updateSettings = new updateSettings();
                    $updateSettings->db = $db;
                    $updated = $updateSettings->query_array('settings', $_POST);
                    if ($updated == 1) {
                        header("Location: " . $CONF['url'] . "/index.php?a=admin&b=manage_notices&m=s");
                    } else {
                        header("Location: " . $CONF['url'] . "/index.php?a=admin&b=manage_notices&m=i");
                    }
                }
            } else {
                $skin = new skin('admin/general');
                $page = '';
                $TMPL['currentTitle'] = $settings['title'];
                $TMPL['currentFormat'] = $settings['format'];
                $TMPL['currentCensor'] = $settings['censor'];
                $TMPL['currentFormatMsg'] = $settings['formatmsg'];
                if ($settings['captcha'] == '1') {
                    $TMPL['on'] = 'selected="selected"';
                } else {
                    $TMPL['off'] = 'selected="selected"';
                }
                if ($settings['smiles'] == '1') {
                    $TMPL['son'] = 'selected="selected"';
                } else {
                    $TMPL['soff'] = 'selected="selected"';
                }
                if ($settings['time'] == '0') {
                    $TMPL['one'] = 'selected="selected"';
                } elseif ($settings['time'] == '1') {
                    $TMPL['two'] = 'selected="selected"';
                } elseif ($settings['time'] == '2') {
                    $TMPL['three'] = 'selected="selected"';
                } else {
                    $TMPL['four'] = 'selected="selected"';
                }
                if ($settings['conline'] == '60') {
                    $TMPL['conone'] = 'selected="selected"';
                } elseif ($settings['conline'] == '300') {
                    $TMPL['contwo'] = 'selected="selected"';
                } else {
                    $TMPL['conthree'] = 'selected="selected"';
                }
                if ($settings['perpage'] == '10') {
                    $TMPL['ten'] = 'selected="selected"';
                } elseif ($settings['perpage'] == '20') {
                    $TMPL['twenty'] = 'selected="selected"';
                } elseif ($settings['perpage'] == '25') {
                    $TMPL['twentyfive'] = 'selected="selected"';
                } else {
                    $TMPL['fifty'] = 'selected="selected"';
                }
                if ($settings['nperpage'] == '10') {
                    $TMPL['nten'] = 'selected="selected"';
                } elseif ($settings['nperpage'] == '25') {
                    $TMPL['ntwentyfive'] = 'selected="selected"';
                } elseif ($settings['nperpage'] == '50') {
                    $TMPL['nfifty'] = 'selected="selected"';
                } else {
                    $TMPL['nonehundred'] = 'selected="selected"';
                }
                if ($settings['mperpage'] == '5') {
                    $TMPL['mone'] = 'selected="selected"';
                } elseif ($settings['mperpage'] == '10') {
                    $TMPL['mtwo'] = 'selected="selected"';
                } elseif ($settings['mperpage'] == '25') {
                    $TMPL['mthree'] = 'selected="selected"';
                } else {
                    $TMPL['mfour'] = 'selected="selected"';
                }
                if ($settings['climit'] == '500') {
                    $TMPL['cone'] = 'selected="selected"';
                } elseif ($settings['climit'] == '1000') {
                    $TMPL['ctwo'] = 'selected="selected"';
                } elseif ($settings['climit'] == '2500') {
                    $TMPL['cthree'] = 'selected="selected"';
                } else {
                    $TMPL['cfour'] = 'selected="selected"';
                }
                if ($settings['chatr'] == '1') {
                    $TMPL['crone'] = 'selected="selected"';
                } elseif ($settings['chatr'] == '2') {
                    $TMPL['crtwo'] = 'selected="selected"';
                } elseif ($settings['chatr'] == '3') {
                    $TMPL['crthree'] = 'selected="selected"';
                } elseif ($settings['chatr'] == '5') {
                    $TMPL['crfive'] = 'selected="selected"';
                } elseif ($settings['chatr'] == '10') {
                    $TMPL['crten'] = 'selected="selected"';
                } elseif ($settings['chatr'] == '30') {
                    $TMPL['crthirty'] = 'selected="selected"';
                } else {
                    $TMPL['croff'] = 'selected="selected"';
                }
                if ($settings['qperpage'] == '10') {
                    $TMPL['qten'] = 'selected="selected"';
                } elseif ($settings['qperpage'] == '25') {
                    $TMPL['qtwentyfive'] = 'selected="selected"';
                } elseif ($settings['qperpage'] == '50') {
                    $TMPL['qfifty'] = 'selected="selected"';
                } else {
                    $TMPL['qonehundred'] = 'selected="selected"';
                }
                if ($settings['cperpage'] == '3') {
                    $TMPL['ctrei'] = 'selected="selected"';
                } elseif ($settings['cperpage'] == '5') {
                    $TMPL['ccinci'] = 'selected="selected"';
                } elseif ($settings['cperpage'] == '10') {
                    $TMPL['czece'] = 'selected="selected"';
                } else {
                    $TMPL['ccinspe'] = 'selected="selected"';
                }
                if ($settings['message'] == '500') {
                    $TMPL['unu'] = 'selected="selected"';
                } elseif ($settings['message'] == '1000') {
                    $TMPL['doi'] = 'selected="selected"';
                } elseif ($settings['message'] == '2500') {
                    $TMPL['trei'] = 'selected="selected"';
                } else {
                    $TMPL['patru'] = 'selected="selected"';
                }
                if ($settings['size'] == '1048576') {
                    $TMPL['onemb'] = 'selected="selected"';
                } elseif ($settings['size'] == '2097152') {
                    $TMPL['twomb'] = 'selected="selected"';
                } elseif ($settings['size'] == '3145728') {
                    $TMPL['threemb'] = 'selected="selected"';
                } else {
                    $TMPL['tenmb'] = 'selected="selected"';
                }
                if ($settings['mail'] == '1') {
                    $TMPL['mailon'] = 'selected="selected"';
                } else {
                    $TMPL['mailoff'] = 'selected="selected"';
                }
                if ($settings['intervalm'] == '10000') {
                    $TMPL['intone'] = 'selected="selected"';
                } elseif ($settings['intervalm'] == '30000') {
                    $TMPL['inttwo'] = 'selected="selected"';
                } elseif ($settings['intervalm'] == '60000') {
                    $TMPL['intthree'] = 'selected="selected"';
                } elseif ($settings['intervalm'] == '120000') {
                    $TMPL['intfour'] = 'selected="selected"';
                } elseif ($settings['intervalm'] == '300000') {
                    $TMPL['intfive'] = 'selected="selected"';
                } elseif ($settings['intervalm'] == '600000') {
                    $TMPL['intsix'] = 'selected="selected"';
                } else {
                    $TMPL['intseven'] = 'selected="selected"';
                }
                if ($settings['intervaln'] == '10000') {
                    $TMPL['intonen'] = 'selected="selected"';
                } elseif ($settings['intervaln'] == '30000') {
                    $TMPL['inttwon'] = 'selected="selected"';
                } elseif ($settings['intervaln'] == '60000') {
                    $TMPL['intthreen'] = 'selected="selected"';
                } elseif ($settings['intervaln'] == '120000') {
                    $TMPL['intfourn'] = 'selected="selected"';
                } elseif ($settings['intervaln'] == '300000') {
                    $TMPL['intfiven'] = 'selected="selected"';
                } elseif ($settings['intervaln'] == '600000') {
                    $TMPL['intsixn'] = 'selected="selected"';
                } else {
                    $TMPL['intsevenn'] = 'selected="selected"';
                }
                if ($settings['sizemsg'] == '1048576') {
                    $TMPL['onembMsg'] = 'selected="selected"';
                } elseif ($settings['sizemsg'] == '2097152') {
                    $TMPL['twombMsg'] = 'selected="selected"';
                } elseif ($settings['sizemsg'] == '3145728') {
                    $TMPL['threembMsg'] = 'selected="selected"';
                } else {
                    $TMPL['tenmbMsg'] = 'selected="selected"';
                }
                if ($settings['uperpage'] == '10') {
                    $TMPL['upone'] = 'selected="selected"';
                } elseif ($settings['uperpage'] == '20') {
                    $TMPL['uptwo'] = 'selected="selected"';
                } elseif ($settings['uperpage'] == '50') {
                    $TMPL['upthree'] = 'selected="selected"';
                } else {
                    $TMPL['upfour'] = 'selected="selected"';
                }
                if ($settings['rperpage'] == '10') {
                    $TMPL['rpone'] = 'selected="selected"';
                } elseif ($settings['rperpage'] == '20') {
                    $TMPL['rptwo'] = 'selected="selected"';
                } elseif ($settings['rperpage'] == '50') {
                    $TMPL['rpthree'] = 'selected="selected"';
                } else {
                    $TMPL['rpfour'] = 'selected="selected"';
                }
                if ($settings['sperpage'] == '10') {
                    $TMPL['sone'] = 'selected="selected"';
                } elseif ($settings['sperpage'] == '20') {
                    $TMPL['stwo'] = 'selected="selected"';
                } elseif ($settings['sperpage'] == '25') {
                    $TMPL['sthree'] = 'selected="selected"';
                } else {
                    $TMPL['sfour'] = 'selected="selected"';
                }
                if (isset($_POST['submit'])) {
                    // Unset the submit array element
                    unset($_POST['submit']);
                    $updateSettings = new updateSettings();
                    $updateSettings->db = $db;
                    $updated = $updateSettings->query_array('settings', $_POST);
                    if ($updated == 1) {
                        header("Location: " . $CONF['url'] . "/index.php?a=admin&m=s");
                    } else {
                        header("Location: " . $CONF['url'] . "/index.php?a=admin&m=i");
                    }
                }
                if ($_GET['m'] == 's') {
                    $TMPL['message'] = notificationBox('success', $LNG['settings_saved'], $LNG['general_settings_saved']);
                } elseif ($_GET['m'] == 'i') {
                    $TMPL['message'] = notificationBox('info', $LNG['nothing_saved'], $LNG['general_settings_unaffected']);
                }
            }
            $page .= $skin->make();
            $TMPL = $TMPL_old;
            unset($TMPL_old);
            $TMPL['settings'] = $page;
            if (isset($_GET['logout']) == 1) {
                $loggedInAdmin->logOut();
                header("Location: " . $CONF['url'] . "/index.php?a=admin");
            }
        } else {
            // Set the content to false, change the $skin to log-in.
            $content = false;
        }
    }
    // Bold the current link
    if (isset($_GET['b'])) {
        $LNG["admin_menu_{$_GET['b']}"] = '<strong>' . $LNG["admin_menu_{$_GET['b']}"] . '</strong>';
        $TMPL['welcome'] = '<strong>' . $LNG["admin_ttl_{$_GET['b']}"] . '</strong>';
    } else {
        $LNG["admin_menu_general"] = '<strong>' . $LNG["admin_menu_general"] . '</strong>';
        $TMPL['welcome'] = '<strong>' . $LNG["admin_ttl_general"] . '</strong>';
    }
    $TMPL['admin_menu'] = '
	<a href="' . $CONF['url'] . '/index.php?a=admin">' . $LNG['admin_menu_general'] . '</a>
	<a href="' . $CONF['url'] . '/index.php?a=admin&b=users_settings">' . $LNG['admin_menu_users_settings'] . '</a>
	<a href="' . $CONF['url'] . '/index.php?a=admin&b=stats">' . $LNG['admin_menu_stats'] . '</a>
	<a href="' . $CONF['url'] . '/index.php?a=admin&b=security">' . $LNG['admin_menu_security'] . '</a>
	<a href="' . $CONF['url'] . '/index.php?a=admin&b=users">' . $LNG['admin_menu_users'] . '</a>
	<a href="' . $CONF['url'] . '/index.php?a=admin&b=manage_reports">' . $LNG['admin_menu_manage_reports'] . '</a>
	<a href="' . $CONF['url'] . '/index.php?a=admin&b=manage_notices">' . $LNG['admin_menu_manage_notices'] . '</a>
	<a href="' . $CONF['url'] . '/index.php?a=admin&logout=1">' . $LNG['admin_menu_logout'] . '</a>';
    $TMPL['url'] = $CONF['url'];
    $TMPL['localurl'] = $CONF['url'];
    $TMPL['titleh'] = $settings['title'];
    $TMPL['title'] = $LNG['title_admin'] . ' - ' . $settings['title'];
    if ($content) {
        $skin = new skin('admin/content');
    } else {
        $skin = new skin('admin/login');
    }
    return $skin->make();
}
Beispiel #9
0
function PageMain()
{
    global $TMPL, $LNG, $CONF, $db, $loggedIn, $settings;
    unset($_POST['suspended']);
    if (isset($_SESSION['username']) && isset($_SESSION['password']) || isset($_COOKIE['username']) && isset($_COOKIE['password'])) {
        $verify = $loggedIn->verify();
        if ($verify['username']) {
            $TMPL_old = $TMPL;
            $TMPL = array();
            $TMPL['url'] = $CONF['url'];
            if ($_GET['b'] == 'security') {
                $skin = new skin('settings/security');
                $page = '';
                // Create the class instance
                $updateUserSettings = new updateUserSettings();
                $updateUserSettings->db = $db;
                $updateUserSettings->id = $verify['idu'];
                if (!empty($_POST)) {
                    $TMPL['message'] = $updateUserSettings->query_array('users', $_POST);
                }
                $userSettings = $updateUserSettings->getSettings();
            } elseif ($_GET['b'] == 'avatar') {
                $skin = new skin('settings/avatar');
                $page = '';
                // Create the class instance
                $updateUserSettings = new updateUserSettings();
                $updateUserSettings->db = $db;
                $updateUserSettings->id = $verify['idu'];
                $TMPL['image'] = '<img src="' . $CONF['url'] . '/thumb.php?src=' . $verify['image'] . '&t=a" width="80" height="80" />';
                $TMPL['cover'] = '<img src="' . $CONF['url'] . '/thumb.php?src=' . $verify['cover'] . '&t=c&w=900&h=200" />';
                $maxsize = $settings['size'];
                if (isset($_FILES['avatarselect']['name'])) {
                    foreach ($_FILES['avatarselect']['error'] as $key => $error) {
                        $ext = pathinfo($_FILES['avatarselect']['name'][$key], PATHINFO_EXTENSION);
                        $size = $_FILES['avatarselect']['size'][$key];
                        $allowedExt = explode(',', strtolower($settings['format']));
                        // Get file type validation
                        $image = validateFile($_FILES['avatarselect']['tmp_name'][$key], $_FILES['avatarselect']['name'][$key], $allowedExt, 0);
                        if ($image['valid'] && $size < $maxsize && $size > 0 && !empty($image['width']) && !empty($image['height'])) {
                            $rand = mt_rand();
                            $tmp_name = $_FILES['avatarselect']['tmp_name'][$key];
                            $name = pathinfo($_FILES['avatarselect']['name'][$key], PATHINFO_FILENAME);
                            $fullname = $_FILES['avatarselect']['name'][$key];
                            $size = $_FILES['avatarselect']['size'][$key];
                            $type = pathinfo($_FILES['avatarselect']['name'][$key], PATHINFO_EXTENSION);
                            $finalName = mt_rand() . '_' . mt_rand() . '_' . mt_rand() . '.' . $db->real_escape_string($ext);
                            // Fix image orientation if possible
                            imageOrientation($tmp_name);
                            // Move the file into the uploaded folder
                            move_uploaded_file($tmp_name, 'uploads/avatars/' . $finalName);
                            // Send the image name in array format to the function
                            $image = array('image' => $finalName);
                            $updateUserSettings->query_array('users', $image);
                            header("Location: " . $CONF['url'] . "/index.php?a=settings&b=avatar&m=s");
                        } elseif ($_FILES['avatarselect']['name'][$key] == '') {
                            // If no file is selected
                            header("Location: " . $CONF['url'] . "/index.php?a=settings&b=avatar&m=nf");
                        } elseif ($size > $maxsize || $size == 0) {
                            // If the file size is higher than allowed or 0
                            header("Location: " . $CONF['url'] . "/index.php?a=settings&b=avatar&m=fs");
                        } else {
                            // If the file format is not allowed
                            header("Location: " . $CONF['url'] . "/index.php?a=settings&b=avatar&m=wf");
                        }
                    }
                }
                if (isset($_FILES['coverselect']['name'])) {
                    foreach ($_FILES['coverselect']['error'] as $key => $error) {
                        $ext = pathinfo($_FILES['coverselect']['name'][$key], PATHINFO_EXTENSION);
                        $size = $_FILES['coverselect']['size'][$key];
                        $allowedExt = explode(',', strtolower($settings['format']));
                        // Get file type validation
                        $image = validateFile($_FILES['coverselect']['tmp_name'][$key], $_FILES['coverselect']['name'][$key], $allowedExt, 0);
                        if ($image['valid'] && $size < $maxsize && $size > 0 && !empty($image['width']) && !empty($image['height'])) {
                            $rand = mt_rand();
                            $tmp_name = $_FILES['coverselect']['tmp_name'][$key];
                            $name = pathinfo($_FILES['coverselect']['name'][$key], PATHINFO_FILENAME);
                            $fullname = $_FILES['coverselect']['name'][$key];
                            $size = $_FILES['coverselect']['size'][$key];
                            $type = pathinfo($_FILES['coverselect']['name'][$key], PATHINFO_EXTENSION);
                            $finalName = mt_rand() . '_' . mt_rand() . '_' . mt_rand() . '.' . $db->real_escape_string($ext);
                            // Fix image orientation if possible
                            imageOrientation($tmp_name);
                            // Move the file into the uploaded folder
                            move_uploaded_file($tmp_name, 'uploads/covers/' . $finalName);
                            // Send the image name in array format to the function
                            $image = array('cover' => $finalName);
                            $updateUserSettings->query_array('users', $image);
                            header("Location: " . $CONF['url'] . "/index.php?a=settings&b=avatar&m=s");
                        } elseif ($_FILES['coverselect']['name'][$key] == '') {
                            // If no file is selected
                            header("Location: " . $CONF['url'] . "/index.php?a=settings&b=avatar&m=nf");
                        } elseif ($size > $maxsize || $size == 0) {
                            // If the file size is higher than allowed or 0
                            header("Location: " . $CONF['url'] . "/index.php?a=settings&b=avatar&m=fs");
                        } else {
                            // If the file format is not allowed
                            header("Location: " . $CONF['url'] . "/index.php?a=settings&b=avatar&m=wf");
                        }
                    }
                }
                if ($_GET['m'] == 's') {
                    $TMPL['message'] = notificationBox('success', $LNG['profile_picture_saved']);
                } elseif ($_GET['m'] == 'nf') {
                    $TMPL['message'] = notificationBox('error', $LNG['no_file']);
                } elseif ($_GET['m'] == 'fs') {
                    $TMPL['message'] = notificationBox('error', sprintf($LNG['file_exceeded'], round($maxsize / 1048576, 2)));
                } elseif ($_GET['m'] == 'wf') {
                    $TMPL['message'] = notificationBox('error', sprintf($LNG['file_format'], $settings['format']));
                }
            } elseif ($_GET['b'] == 'social') {
                $skin = new skin('settings/social');
                $page = '';
                // Create the class instance
                $updateUserSettings = new updateUserSettings();
                $updateUserSettings->db = $db;
                $updateUserSettings->id = $verify['idu'];
                if (!empty($_POST)) {
                    $TMPL['message'] = $updateUserSettings->query_array('users', array_map("strip_tags_array", $_POST));
                }
                $userSettings = $updateUserSettings->getSettings();
                $TMPL['currentFacebook'] = $userSettings['facebook'];
                $TMPL['currentTwitter'] = $userSettings['twitter'];
                $TMPL['currentGplus'] = $userSettings['gplus'];
                $TMPL['currentYouTube'] = $userSettings['youtube'];
                $TMPL['currentSoundCloud'] = $userSettings['soundcloud'];
                $TMPL['currentLastfm'] = $userSettings['lastfm'];
                $TMPL['currentMySpace'] = $userSettings['myspace'];
                $TMPL['currentVimeo'] = $userSettings['vimeo'];
                $TMPL['currentTumblr'] = $userSettings['tumblr'];
            } elseif ($_GET['b'] == 'notifications') {
                $skin = new skin('settings/notifications');
                $page = '';
                // Create the class instance
                $updateUserSettings = new updateUserSettings();
                $updateUserSettings->db = $db;
                $updateUserSettings->id = $verify['idu'];
                if (!empty($_POST)) {
                    $TMPL['message'] = $updateUserSettings->query_array('users', array_map("strip_tags_array", $_POST));
                }
                $userSettings = $updateUserSettings->getSettings();
                if ($userSettings['notificationl'] == '0') {
                    $TMPL['loff'] = 'selected="selected"';
                } else {
                    $TMPL['lon'] = 'selected="selected"';
                }
                if ($userSettings['notificationc'] == '0') {
                    $TMPL['coff'] = 'selected="selected"';
                } else {
                    $TMPL['con'] = 'selected="selected"';
                }
                if ($userSettings['notificationd'] == '0') {
                    $TMPL['doff'] = 'selected="selected"';
                } else {
                    $TMPL['don'] = 'selected="selected"';
                }
                if ($userSettings['notificationf'] == '0') {
                    $TMPL['foff'] = 'selected="selected"';
                } else {
                    $TMPL['fon'] = 'selected="selected"';
                }
                if ($userSettings['email_comment'] == '0') {
                    $TMPL['ecoff'] = 'selected="selected"';
                } else {
                    $TMPL['econ'] = 'selected="selected"';
                }
                if ($userSettings['email_like'] == '0') {
                    $TMPL['eloff'] = 'selected="selected"';
                } else {
                    $TMPL['elon'] = 'selected="selected"';
                }
                if ($userSettings['email_new_friend'] == '0') {
                    $TMPL['enfoff'] = 'selected="selected"';
                } else {
                    $TMPL['enfon'] = 'selected="selected"';
                }
            } else {
                $skin = new skin('settings/general');
                $page = '';
                // Create the class instance
                $updateUserSettings = new updateUserSettings();
                $updateUserSettings->db = $db;
                $updateUserSettings->id = $verify['idu'];
                if (!empty($_POST)) {
                    $TMPL['message'] = $updateUserSettings->query_array('users', array_map("strip_tags_array", $_POST));
                }
                $userSettings = $updateUserSettings->getSettings();
                $TMPL['countries'] = countries(1, $userSettings['country']);
                $TMPL['currentFirstName'] = $userSettings['first_name'];
                $TMPL['currentLastName'] = $userSettings['last_name'];
                $TMPL['currentEmail'] = $userSettings['email'];
                $TMPL['currentCity'] = $userSettings['city'];
                $TMPL['currentWebsite'] = $userSettings['website'];
                $TMPL['currentDescription'] = $userSettings['description'];
                if ($userSettings['private'] == '1') {
                    $TMPL['on'] = 'selected="selected"';
                } elseif ($userSettings['private'] == '2') {
                    $TMPL['semi'] = 'selected="selected"';
                } else {
                    $TMPL['off'] = 'selected="selected"';
                }
                if ($userSettings['offline'] == '1') {
                    $TMPL['con'] = 'selected="selected"';
                } else {
                    $TMPL['coff'] = 'selected="selected"';
                }
            }
            $page .= $skin->make();
            $TMPL = $TMPL_old;
            unset($TMPL_old);
            $TMPL['settings'] = $page;
        } else {
            // If fake cookies are set, or they are set wrong, delete everything and redirect to home-page
            $loggedIn->logOut();
            header("Location: " . $CONF['url'] . "/index.php?a=welcome");
        }
    } else {
        // If the session or cookies are not set, redirect to home-page
        header("Location: " . $CONF['url'] . "/index.php?a=welcome");
    }
    // Bold the current link
    if (isset($_GET['b'])) {
        $LNG["user_menu_{$_GET['b']}"] = '<strong>' . $LNG["user_menu_{$_GET['b']}"] . '</strong>';
        $TMPL['welcome'] = $LNG["user_ttl_{$_GET['b']}"];
    } else {
        $LNG["user_menu_general"] = '<strong>' . $LNG["user_menu_general"] . '</strong>';
        $TMPL['welcome'] = $LNG["user_ttl_general"];
    }
    $TMPL['user_menu'] = '
	<a href="' . $CONF['url'] . '/index.php?a=settings" rel="loadpage">' . $LNG['user_menu_general'] . '</a> 
	<a href="' . $CONF['url'] . '/index.php?a=settings&b=avatar" rel="loadpage">' . $LNG['user_menu_avatar'] . '</a>
	<a href="' . $CONF['url'] . '/index.php?a=settings&b=notifications" rel="loadpage">' . $LNG['user_menu_notifications'] . '</a>
	<a href="' . $CONF['url'] . '/index.php?a=settings&b=social" rel="loadpage">' . $LNG['user_menu_social'] . '</a>
	<a href="' . $CONF['url'] . '/index.php?a=settings&b=security" rel="loadpage">' . $LNG['user_menu_security'] . '</a>
	' . ($settings['paypalapp'] ? '<a href="' . $CONF['url'] . '/index.php?a=pro" rel="loadpage">' . $LNG['user_menu_plan'] . '</a>' : '');
    $TMPL['title'] = $LNG['title_settings'] . ' - ' . $settings['title'];
    $skin = new skin('settings/content');
    return $skin->make();
}
function PageMain()
{
    global $TMPL, $LNG, $CONF, $db, $loggedIn, $settings;
    if (isset($_SESSION['username']) && isset($_SESSION['password']) || isset($_COOKIE['username']) && isset($_COOKIE['password'])) {
        $verify = $loggedIn->verify();
        if ($verify['username']) {
            $TMPL_old = $TMPL;
            $TMPL = array();
            $TMPL['url'] = $CONF['url'];
            if ($_GET['b'] == 'security') {
                $skin = new skin('settings/security');
                $page = '';
                // Create the class instance
                $updateUserSettings = new updateUserSettings();
                $updateUserSettings->db = $db;
                $updateUserSettings->id = $verify['idu'];
                if (!empty($_POST)) {
                    // Unset the verified value if exist, by unsetting it here and not in the class, I'm allowing the Admin to change this value
                    unset($_POST['verified']);
                    $TMPL['message'] = $updateUserSettings->query_array('users', $_POST);
                }
                $userSettings = $updateUserSettings->getSettings();
                $page .= $skin->make();
            } elseif ($_GET['b'] == 'avatar') {
                $skin = new skin('settings/avatar');
                $page = '';
                // Create the class instance
                $updateUserSettings = new updateUserSettings();
                $updateUserSettings->db = $db;
                $updateUserSettings->id = $verify['idu'];
                $TMPL['image'] = '<img src="' . $CONF['url'] . '/thumb.php?src=' . $verify['image'] . '&t=a" width="80" height="80" />';
                $TMPL['cover'] = '<img src="' . $CONF['url'] . '/thumb.php?src=' . $verify['cover'] . '&t=c&w=900&h=200" />';
                $maxsize = $settings['size'];
                if (isset($_FILES['avatarselect']['name'])) {
                    foreach ($_FILES['avatarselect']['error'] as $key => $error) {
                        $ext = pathinfo($_FILES['avatarselect']['name'][$key], PATHINFO_EXTENSION);
                        $size = $_FILES['avatarselect']['size'][$key];
                        $extArray = explode(',', $settings['format']);
                        // Get the image size
                        list($width, $height) = getimagesize($_FILES['avatarselect']['tmp_name'][0]);
                        $ratio = $width / $height;
                        if (in_array(strtolower($ext), $extArray) && $size < $maxsize && $size > 0 && !empty($width) && !empty($height)) {
                            $rand = mt_rand();
                            $tmp_name = $_FILES['avatarselect']['tmp_name'][$key];
                            $name = pathinfo($_FILES['avatarselect']['name'][$key], PATHINFO_FILENAME);
                            $fullname = $_FILES['avatarselect']['name'][$key];
                            $size = $_FILES['avatarselect']['size'][$key];
                            $type = pathinfo($_FILES['avatarselect']['name'][$key], PATHINFO_EXTENSION);
                            $finalName = mt_rand() . '_' . mt_rand() . '_' . mt_rand() . '.' . $db->real_escape_string($ext);
                            // Move the file into the uploaded folder
                            move_uploaded_file($tmp_name, 'uploads/avatars/' . $finalName);
                            // Send the image name in array format to the function
                            $image = array('image' => $finalName);
                            $updateUserSettings->query_array('users', $image);
                            header("Location: " . $CONF['url'] . "/index.php?a=settings&b=avatar&m=s");
                        } elseif ($_FILES['avatarselect']['name'][$key] == '') {
                            //Daca nu este selectata nici o fila.
                            header("Location: " . $CONF['url'] . "/index.php?a=settings&b=avatar&m=nf");
                        } elseif ($size > $maxsize || $size == 0) {
                            //Daca fila are dimensiunea mai mare decat dimensiunea admisa, sau egala cu 0.
                            header("Location: " . $CONF['url'] . "/index.php?a=settings&b=avatar&m=fs");
                        } else {
                            //Daca formatul filei nu este un format admis.
                            header("Location: " . $CONF['url'] . "/index.php?a=settings&b=avatar&m=wf");
                        }
                    }
                }
                if (isset($_FILES['coverselect']['name'])) {
                    foreach ($_FILES['coverselect']['error'] as $key => $error) {
                        $ext = pathinfo($_FILES['coverselect']['name'][$key], PATHINFO_EXTENSION);
                        $size = $_FILES['coverselect']['size'][$key];
                        $extArray = explode(',', $settings['format']);
                        // Get the image size
                        list($width, $height) = getimagesize($_FILES['coverselect']['tmp_name'][0]);
                        $ratio = $width / $height;
                        if (in_array(strtolower($ext), $extArray) && $size < $maxsize && $size > 0 && !empty($width) && !empty($height)) {
                            $rand = mt_rand();
                            $tmp_name = $_FILES['coverselect']['tmp_name'][$key];
                            $name = pathinfo($_FILES['coverselect']['name'][$key], PATHINFO_FILENAME);
                            $fullname = $_FILES['coverselect']['name'][$key];
                            $size = $_FILES['coverselect']['size'][$key];
                            $type = pathinfo($_FILES['coverselect']['name'][$key], PATHINFO_EXTENSION);
                            $finalName = mt_rand() . '_' . mt_rand() . '_' . mt_rand() . '.' . $db->real_escape_string($ext);
                            // Move the file into the uploaded folder
                            move_uploaded_file($tmp_name, 'uploads/covers/' . $finalName);
                            // Send the image name in array format to the function
                            $image = array('cover' => $finalName);
                            $updateUserSettings->query_array('users', $image);
                            header("Location: " . $CONF['url'] . "/index.php?a=settings&b=avatar&m=s");
                        } elseif ($_FILES['coverselect']['name'][$key] == '') {
                            //Daca nu este selectata nici o fila.
                            header("Location: " . $CONF['url'] . "/index.php?a=settings&b=avatar&m=nf");
                        } elseif ($size > $maxsize || $size == 0) {
                            //Daca fila are dimensiunea mai mare decat dimensiunea admisa, sau egala cu 0.
                            header("Location: " . $CONF['url'] . "/index.php?a=settings&b=avatar&m=fs");
                        } else {
                            //Daca formatul filei nu este un format admis.
                            header("Location: " . $CONF['url'] . "/index.php?a=settings&b=avatar&m=wf");
                        }
                    }
                }
                if ($_GET['m'] == 's') {
                    $TMPL['message'] = notificationBox('success', $LNG['image_saved'], $LNG['profile_picture_saved']);
                } elseif ($_GET['m'] == 'nf') {
                    $TMPL['message'] = notificationBox('error', $LNG['error'], $LNG['no_file']);
                } elseif ($_GET['m'] == 'fs') {
                    $TMPL['message'] = notificationBox('error', $LNG['error'], sprintf($LNG['file_exceeded'], round($maxsize / 1048576, 2)));
                } elseif ($_GET['m'] == 'wf') {
                    $TMPL['message'] = notificationBox('error', $LNG['error'], sprintf($LNG['file_format'], $settings['format']));
                } elseif ($_GET['m'] == 'de') {
                    $TMPL['message'] = notificationBox('success', $LNG['image_removed'], $LNG['profile_picture_removed']);
                }
                $page .= $skin->make();
            } elseif ($_GET['b'] == 'notifications') {
                $skin = new skin('settings/notifications');
                $page = '';
                // Create the class instance
                $updateUserSettings = new updateUserSettings();
                $updateUserSettings->db = $db;
                $updateUserSettings->id = $verify['idu'];
                if (!empty($_POST)) {
                    // Unset the verified value if exist, by unsetting it here and not in the class, I'm allowing the Admin to change this value
                    unset($_POST['verified']);
                    $TMPL['message'] = $updateUserSettings->query_array('users', array_map("strip_tags_array", $_POST));
                }
                $userSettings = $updateUserSettings->getSettings();
                if ($userSettings['notificationl'] == '0') {
                    $TMPL['loff'] = 'selected="selected"';
                } else {
                    $TMPL['lon'] = 'selected="selected"';
                }
                if ($userSettings['notificationc'] == '0') {
                    $TMPL['coff'] = 'selected="selected"';
                } else {
                    $TMPL['con'] = 'selected="selected"';
                }
                if ($userSettings['notifications'] == '0') {
                    $TMPL['soff'] = 'selected="selected"';
                } else {
                    $TMPL['son'] = 'selected="selected"';
                }
                if ($userSettings['notificationd'] == '0') {
                    $TMPL['doff'] = 'selected="selected"';
                } else {
                    $TMPL['don'] = 'selected="selected"';
                }
                if ($userSettings['notificationf'] == '0') {
                    $TMPL['foff'] = 'selected="selected"';
                } else {
                    $TMPL['fon'] = 'selected="selected"';
                }
                if ($userSettings['sound_new_notification'] == '0') {
                    $TMPL['snnoff'] = 'selected="selected"';
                } else {
                    $TMPL['snnon'] = 'selected="selected"';
                }
                if ($userSettings['sound_new_chat'] == '0') {
                    $TMPL['sncoff'] = 'selected="selected"';
                } else {
                    $TMPL['sncon'] = 'selected="selected"';
                }
                if ($userSettings['email_comment'] == '0') {
                    $TMPL['ecoff'] = 'selected="selected"';
                } else {
                    $TMPL['econ'] = 'selected="selected"';
                }
                if ($userSettings['email_like'] == '0') {
                    $TMPL['eloff'] = 'selected="selected"';
                } else {
                    $TMPL['elon'] = 'selected="selected"';
                }
                if ($userSettings['email_new_friend'] == '0') {
                    $TMPL['enfoff'] = 'selected="selected"';
                } else {
                    $TMPL['enfon'] = 'selected="selected"';
                }
                $page .= $skin->make();
            } else {
                $skin = new skin('settings/general');
                $page = '';
                // Create the class instance
                $updateUserSettings = new updateUserSettings();
                $updateUserSettings->db = $db;
                $updateUserSettings->id = $verify['idu'];
                if (!empty($_POST)) {
                    // Unset the verified value if exist, by unsetting it here and not in the class, I'm allowing the Admin to change this value
                    unset($_POST['verified']);
                    $TMPL['message'] = $updateUserSettings->query_array('users', array_map("strip_tags_array", $_POST));
                }
                $userSettings = $updateUserSettings->getSettings();
                $date = explode('/', $userSettings['born']);
                $TMPL['years'] = generateDateForm(0, $date[2]);
                $TMPL['months'] = generateDateForm(1, $date[1]);
                $TMPL['days'] = generateDateForm(2, $date[0]);
                $TMPL['currentFirstName'] = $userSettings['first_name'];
                $TMPL['currentLastName'] = $userSettings['last_name'];
                $TMPL['currentEmail'] = $userSettings['email'];
                $TMPL['currentLocation'] = $userSettings['location'];
                $TMPL['currentWebsite'] = $userSettings['website'];
                $TMPL['currentBio'] = $userSettings['bio'];
                $TMPL['currentFacebook'] = $userSettings['facebook'];
                $TMPL['currentTwitter'] = $userSettings['twitter'];
                $TMPL['currentGplus'] = $userSettings['gplus'];
                $TMPL['currentEnrollno'] = $userSettings['enrollno'];
                $join = explode('-', $userSettings['join']);
                $TMPL['jyear'] = generateDateForm(0, $join[0]);
                $TMPL['tyear'] = generateDateForm(0, $join[1]);
                if ($userSettings['private'] == '1') {
                    $TMPL['on'] = 'selected="selected"';
                } elseif ($userSettings['private'] == '2') {
                    $TMPL['semi'] = 'selected="selected"';
                } else {
                    $TMPL['off'] = 'selected="selected"';
                }
                if ($userSettings['privacy'] == '0') {
                    $TMPL['pon'] = 'selected="selected"';
                } else {
                    $TMPL['poff'] = 'selected="selected"';
                }
                if ($userSettings['offline'] == '1') {
                    $TMPL['con'] = 'selected="selected"';
                } else {
                    $TMPL['coff'] = 'selected="selected"';
                }
                if ($userSettings['gender'] == '0') {
                    $TMPL['ngender'] = 'selected="selected"';
                } elseif ($userSettings['gender'] == '1') {
                    $TMPL['mgender'] = 'selected="selected"';
                } else {
                    $TMPL['fgender'] = 'selected="selected"';
                }
                if ($userSettings['course'] == 'btech') {
                    $TMPL['btech'] = 'selected="selected"';
                } elseif ($userSettings['course'] == 'mca') {
                    $TMPL['mca'] = 'selected="selected"';
                } elseif ($userSettings['course'] == 'mba') {
                    $TMPL['mba'] = 'selected="selected"';
                }
                if ($userSettings['branch'] == 'ece') {
                    $TMPL['ece'] = 'selected="selected"';
                } elseif ($userSettings['branch'] == 'cse') {
                    $TMPL['cse'] = 'selected="selected"';
                } elseif ($userSettings['branch'] == 'mae') {
                    $TMPL['mae'] = 'selected="selected"';
                } elseif ($userSettings['branch'] == 'eee') {
                    $TMPL['eee'] = 'selected="selected"';
                } elseif ($userSettings['branch'] == 'it') {
                    $TMPL['it'] = 'selected="selected"';
                } elseif ($userSettings['branch'] == 'ce') {
                    $TMPL['ce'] = 'selected="selected"';
                } elseif ($userSettings['branch'] == 'ene') {
                    $TMPL['ene'] = 'selected="selected"';
                }
                $page .= $skin->make();
            }
            $TMPL = $TMPL_old;
            unset($TMPL_old);
            $TMPL['settings'] = $page;
        } else {
            // If fake cookies are set, or they are set wrong, delete everything and redirect to home-page
            $loggedIn->logOut();
            header("Location: " . $CONF['url'] . "/index.php?a=welcome");
        }
    } else {
        // If the session or cookies are not set, redirect to home-page
        header("Location: " . $CONF['url'] . "/index.php?a=welcome");
    }
    // Bold the current link
    if (isset($_GET['b'])) {
        $LNG["user_menu_{$_GET['b']}"] = '<strong>' . $LNG["user_menu_{$_GET['b']}"] . '</strong>';
        $TMPL['welcome'] = '<strong>' . $LNG["user_ttl_{$_GET['b']}"] . '</strong>';
    } else {
        $LNG["user_menu_general"] = '<strong>' . $LNG["user_menu_general"] . '</strong>';
        $TMPL['welcome'] = '<strong>' . $LNG["user_ttl_general"] . '</strong>';
    }
    $TMPL['user_menu'] = '
	<a href="' . $CONF['url'] . '/index.php?a=settings">' . $LNG['user_menu_general'] . '</a> 
	<a href="' . $CONF['url'] . '/index.php?a=settings&b=avatar">' . $LNG['user_menu_avatar'] . '</a>
	<a href="' . $CONF['url'] . '/index.php?a=settings&b=notifications">' . $LNG['user_menu_notifications'] . '</a>
	<a href="' . $CONF['url'] . '/index.php?a=settings&b=security">' . $LNG['user_menu_security'] . '</a>';
    $TMPL['image'] = '<img src="' . $CONF['url'] . '/thumb.php?src=' . $verify['image'] . '&t=a" width="80" height="80" />';
    $TMPL['title'] = $LNG['title_settings'] . ' - ' . $settings['title'];
    $skin = new skin('settings/content');
    return $skin->make();
}
function PageMain()
{
    global $TMPL, $LNG, $CONF, $db, $loggedIn, $settings;
    if (isset($_SESSION['username']) && isset($_SESSION['password']) || isset($_COOKIE['username']) && isset($_COOKIE['password'])) {
        $verify = $loggedIn->verify();
        // If the user is logged in, do not allow him to see this page.
        if ($verify['username']) {
            header("Location: " . $CONF['url'] . "/index.php?a=welcome");
        }
    }
    // New instance of Recover class
    $recover = new recover();
    $recover->db = $db;
    $TMPL_old = $TMPL;
    $TMPL = array();
    $skin = new skin('recover/username');
    $rows = '';
    $TMPL['url'] = $CONF['url'];
    $rows .= $skin->make();
    if (isset($_POST['username']) && empty($_POST['username'])) {
        header("Location: " . $CONF['url'] . "/index.php?a=recover&m=e");
    } elseif (isset($_POST['username']) && !empty($_POST['username'])) {
        $recover->username = $_POST['username'];
        // Save the Result into a list
        list($username, $email, $salted) = $recover->checkUser();
        // If the POST username is the same with the result
        if (strtolower($_POST['username']) == $username || strtolower($_POST['username']) == $email) {
            // Send the recover e-mail
            sendMail($email, $LNG['recover_mail'], sprintf($LNG['recover_content'], $username, $salted, $CONF['url'], $CONF['url']), $CONF['email']);
            header("Location: " . $CONF['url'] . "/index.php?a=recover&r=1&m=s");
        } else {
            header("Location: " . $CONF['url'] . "/index.php?a=recover&m=e");
        }
    }
    // If there is any attempt of sending blank fields replace them.
    $key = str_replace(' ', '1', $_POST['k']);
    if (isset($_GET['r'])) {
        if (empty($_POST['n']) || empty($key) || empty($_POST['u']) && empty($key)) {
            // Change the skin to empty
            $skin = new skin('recover/error');
            $rows = '';
            $TMPL['url'] = $CONF['url'];
            $rows .= $skin->make();
        } elseif (isset($_POST['n']) && isset($key) && isset($_POST['p'])) {
            // Execut the changePassword function
            $changePassword = $recover->changePassword($_POST['n'], $_POST['p'], $_POST['k']);
            // If the password was changed
            if ($changePassword) {
                header("Location: " . $CONF['url'] . "/index.php?a=recover&r=1&m=ps");
            } else {
                header("Location: " . $CONF['url'] . "/index.php?a=recover&r=1&m=wk");
            }
        }
    }
    $TMPL = $TMPL_old;
    unset($TMPL_old);
    $TMPL['rows'] = $rows;
    $TMPL['error'] = $error;
    if ($_GET['m'] == 's') {
        $TMPL['message'] = notificationBox('info', $LNG['email_sent'], $LNG['email_reset']);
    } elseif ($_GET['m'] == 'e') {
        $TMPL['message'] = notificationBox('error', $LNG['error'], $LNG['username_not_found']);
    } elseif ($_GET['m'] == 'wk') {
        $TMPL['message'] = notificationBox('error', $LNG['error'], $LNG['userkey_not_found']);
    } elseif ($_GET['m'] == 'ps') {
        $TMPL['message'] = notificationBox('success', $LNG['password_changed'], $LNG['password_reseted']);
    }
    $TMPL['url'] = $CONF['url'];
    $TMPL['title'] = $LNG['password_recovery'] . ' - ' . $settings['title'];
    $skin = new skin('recover/content');
    return $skin->make();
}
Beispiel #12
0
function PageMain()
{
    global $TMPL, $LNG, $CONF, $db, $loggedIn, $settings;
    if (!$settings['paypalapp']) {
        header("Location: " . $CONF['url'] . "/index.php?a=welcome");
    }
    if (isset($_SESSION['username']) && isset($_SESSION['password']) || isset($_COOKIE['username']) && isset($_COOKIE['password'])) {
        $verify = $loggedIn->verify();
        if (empty($verify['username'])) {
            // If fake cookies are set, or they are set wrong, delete everything and redirect to home-page
            $loggedIn->logOut();
            header("Location: " . $CONF['url'] . "/index.php?a=welcome");
        }
    }
    // Start the music feed
    $feed = new feed();
    $feed->db = $db;
    $feed->url = $CONF['url'];
    $feed->user = $verify;
    $feed->id = $verify['idu'];
    $feed->username = $verify['username'];
    $proAccount = $feed->getProStatus($feed->id, 0);
    $TMPL_old = $TMPL;
    $TMPL = array();
    // Get the PayPal settings
    $PayPalMode = $settings['paypalsand'] ? '.sandbox' : '';
    // Decide whether whether the request is for sandbox or live
    $PayPalCurrencyCode = $settings['currency'];
    // Paypal Currency Code
    $PayPalReturnURL = $CONF['url'] . '/index.php?a=pro&type=successful';
    //Point to process.php page
    $PayPalCancelURL = $CONF['url'] . '/index.php?a=pro&type=canceled';
    // Canceling URL if user clicks cancel
    $paypal = new paypalApi();
    $paypal->username = $settings['paypaluser'];
    // PayPal API Username
    $paypal->password = $settings['paypalpass'];
    // Paypal API password
    $paypal->signature = $settings['paypalsign'];
    // Paypal API Signature
    $skin = new skin('pro/gopro');
    $rows = '';
    // If the user is logged-in
    if ($feed->id) {
        if (isset($_POST['plan']) && !$proAccount) {
            $ItemName = $_POST["plan"] == 1 ? sprintf($LNG['pro_year'], $settings['title']) : sprintf($LNG['pro_month'], $settings['title']);
            //Item Name
            $ItemPrice = $_POST["plan"] == 1 ? $settings['proyear'] : $settings['promonth'];
            //Item Price
            $ItemNumber = $_POST["plan"] == 1 ? md5(1) : md5(0);
            //Item Number
            $ItemDesc = $_POST["plan"] == 1 ? sprintf($LNG['pro_year'], $settings['title']) : sprintf($LNG['pro_month'], $settings['title']);
            //Item Number
            $ItemQty = 1;
            // Item Quantity
            $ItemTotalPrice = $ItemPrice * $ItemQty;
            //(Item Price x Quantity = Total) Get total amount of product;
            // Parameters for SetExpressCheckout, which will be sent to PayPal
            $params = array('METHOD' => 'SetExpressCheckout', 'RETURNURL' => $PayPalReturnURL, 'CANCELURL' => $PayPalCancelURL, 'PAYMENTREQUEST_0_PAYMENTACTION' => 'SALE', 'L_PAYMENTREQUEST_0_NAME0' => $ItemName, 'L_PAYMENTREQUEST_0_NUMBER0' => $ItemNumber, 'L_PAYMENTREQUEST_0_DESC0' => $ItemDesc, 'L_PAYMENTREQUEST_0_AMT0' => $ItemPrice, 'L_PAYMENTREQUEST_0_QTY0' => $ItemQty, 'NOSHIPPING' => 0, 'PAYMENTREQUEST_0_ITEMAMT' => $ItemTotalPrice, 'PAYMENTREQUEST_0_AMT' => $ItemPrice, 'PAYMENTREQUEST_0_CURRENCYCODE' => $PayPalCurrencyCode, 'PAYMENTREQUEST_0_ALLOWEDPAYMENTMETHOD' => 'InstantPaymentOnly', 'LOCALECODE' => 'US', 'LOGOIMG' => $CONF['url'] . '/' . $CONF['theme_url'] . '/images/logo_black.png', 'CARTBORDERCOLOR' => 'FFFFFF', 'ALLOWNOTE' => 0);
            // Store the selected plan
            $_SESSION['SelectedPlan'] = $_POST['plan'];
            $_SESSION['ItemName'] = $ItemName;
            //Item Name
            $_SESSION['ItemPrice'] = $ItemPrice;
            //Item Price
            $_SESSION['ItemNumber'] = $ItemNumber;
            //Item Number
            $_SESSION['ItemDesc'] = $ItemDesc;
            //Item Number
            $_SESSION['ItemQty'] = $ItemQty;
            // Item Quantity
            $_SESSION['ItemTotalPrice'] = $ItemTotalPrice;
            //(Item Price x Quantity = Total) Get total amount of product;
            // Execute SetExpressCheckOut method to create the payment token and PayerID
            $paypalResponse = $paypal->post('SetExpressCheckout', $params, $PayPalMode);
            //Respond according to message we receive from Paypal
            if (strtoupper($paypalResponse["ACK"]) == "SUCCESS") {
                // Generat the PayPal payment url with the response Token
                $paypalurl = 'https://www' . $PayPalMode . '.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=' . $paypalResponse["TOKEN"] . '';
                // Redirect to PayPal payment page
                header('Location: ' . $paypalurl);
            } else {
                // If the payment is not successful
                $TMPL['error'] = notificationBox('error', '<strong>' . urldecode($paypalResponse['L_SHORTMESSAGE0'] . '</strong>: ' . $paypalResponse['L_LONGMESSAGE0']));
            }
        } elseif ($_GET['type'] == 'canceled' && !$proAccount) {
            // If the payment has been canceled
            $TMPL['error'] = notificationBox('error', $LNG['payment_error_1']);
        } elseif ($_GET['type'] == 'successful' && !$proAccount) {
            $skin = new skin('pro/gopro');
            $rows = '';
            // If the token and PayerID has been returned by the Return URL
            if (isset($_GET["token"]) && isset($_GET["PayerID"])) {
                $token = $_GET["token"];
                $payer_id = $_GET["PayerID"];
                // Get the selected plan
                $ItemName = $_SESSION['ItemName'];
                //Item Name
                $ItemPrice = $_SESSION['ItemPrice'];
                //Item Price
                $ItemNumber = $_SESSION['ItemNumber'];
                //Item Number
                $ItemDesc = $_SESSION['ItemDesc'];
                //Item Number
                $ItemQty = $_SESSION['ItemQty'];
                // Item Quantity
                $ItemTotalPrice = $_SESSION['ItemTotalPrice'];
                $params = array('TOKEN' => $token, 'PAYERID' => $payer_id, 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', 'L_PAYMENTREQUEST_0_NAME0' => $ItemName, 'L_PAYMENTREQUEST_0_NUMBER0' => $ItemNumber, 'L_PAYMENTREQUEST_0_DESC0' => $ItemDesc, 'L_PAYMENTREQUEST_0_AMT0' => $ItemPrice, 'L_PAYMENTREQUEST_0_QTY0' => $ItemQty, 'PAYMENTREQUEST_0_ITEMAMT' => $ItemTotalPrice, 'PAYMENTREQUEST_0_AMT' => $ItemPrice, 'PAYMENTREQUEST_0_CURRENCYCODE' => $PayPalCurrencyCode, 'PAYMENTREQUEST_0_ALLOWEDPAYMENTMETHOD' => 'InstantPaymentOnly');
                // Execute DoExpressCheckoutPayment to receive the payment from the user
                $paypalResponse = $paypal->post('DoExpressCheckoutPayment', $params, $PayPalMode);
                // Check if the payment was successful
                if (strtoupper($paypalResponse["ACK"]) == "SUCCESS") {
                    // Verify if the payment is Completed
                    if ($paypalResponse["PAYMENTINFO_0_PAYMENTSTATUS"] == 'Completed') {
                        // Execute GetExpressCheckoutDetails to retrieve the transaction details
                        $params = array('TOKEN' => $token);
                        $paypalResponse = $paypal->post('GetExpressCheckoutDetails', $params, $PayPalMode);
                        // If the GetExpressCheckoutDetails was successful
                        if (strtoupper($paypalResponse["ACK"]) == "SUCCESS") {
                            $date = date("Y-m-d H:m:s", strtotime($_SESSION['SelectedPlan'] == 1 ? "+1 year" : "+1 month"));
                            $stmt = $db->prepare(sprintf("INSERT INTO `payments`\n\t\t\t\t\t\t\t\t(`by`, `payer_id`, `payer_first_name`, `payer_last_name`, `payer_email`, `payer_country`, `txn_id`, `amount`, `currency`, `type`, `status`, `valid`, `time`) VALUES \n\t\t\t\t\t\t\t\t('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s','%s', '%s', '%s', '%s')", $db->real_escape_string($feed->id), $db->real_escape_string($paypalResponse['PAYERID']), $db->real_escape_string($paypalResponse['FIRSTNAME']), $db->real_escape_string($paypalResponse['LASTNAME']), $db->real_escape_string($paypalResponse['EMAIL']), $db->real_escape_string($paypalResponse['SHIPTOCOUNTRYNAME']), $db->real_escape_string($paypalResponse['PAYMENTREQUEST_0_TRANSACTIONID']), $db->real_escape_string($paypalResponse['AMT']), $settings['currency'], $_SESSION['SelectedPlan'], 1, $date, date("Y-m-d H:m:s")));
                            // Execute the statement
                            $stmt->execute();
                            // Check the affected rows
                            $affected = $stmt->affected_rows;
                            // Close the statement
                            $stmt->close();
                            // If the pro status has been added
                            if ($affected) {
                                // Set the pro account to valid
                                $proAccount = 2;
                            }
                        } else {
                            $TMPL['error'] = notificationBox('error', '<strong>' . urldecode($paypalResponse['L_SHORTMESSAGE0'] . '</strong>: ' . $paypalResponse['L_LONGMESSAGE0']));
                        }
                    } else {
                        $TMPL['error'] = notificationBox('error', '<strong>' . urldecode($paypalResponse['L_SHORTMESSAGE0'] . '</strong>: ' . $paypalResponse['L_LONGMESSAGE0']));
                    }
                } else {
                    $TMPL['error'] = notificationBox('error', '<strong>' . urldecode($paypalResponse['L_SHORTMESSAGE0'] . '</strong>: ' . $paypalResponse['L_LONGMESSAGE0']));
                }
            }
        }
        if ($proAccount) {
            $skin = new skin('pro/successful');
            $rows = '';
            $transaction = $feed->getProStatus($feed->id, 2);
            // If the proAccount was just created
            if ($proAccount == 2) {
                $TMPL['pro_title'] = $LNG['congratulations'] . '!';
                $TMPL['pro_title_desc'] = $LNG['go_pro_congrats'];
            } else {
                $TMPL['pro_title'] = $LNG['pro_plan'];
                $TMPL['pro_title_desc'] = $LNG['account_status'];
            }
            // Explode the date to display in a custom format
            $valid = explode('-', $transaction['valid']);
            $TMPL['validuntil'] = $valid[0] . '-' . $valid[1] . '-' . substr($valid[2], 0, 2);
            // Decide the plan type
            $TMPL['plan'] = $transaction['amount'] == $settings['proyear'] ? $LNG['yearly'] : $LNG['monthly'];
            // Days left of pro Plan
            $TMPL['daysleft'] = floor((strtotime($transaction['valid']) - strtotime(date("Y-m-d H:i:s"))) / (60 * 60 * 24)) . ' ' . $LNG['days_left'];
            // The Amount paid for the pro plan
            $TMPL['amount'] = $transaction['amount'] . ' ' . $settings['currency'];
        }
        $TMPL['go_pro_action'] = 'formSubmit(\'gopro-form\')';
    } else {
        $TMPL['go_pro_action'] = 'connect_modal()';
    }
    $TMPL['history'] = $feed->proAccountHistory(null, 1, 1);
    $TMPL['protracksize'] = fsize($settings['protracksize']);
    $TMPL['protracktotal'] = fsize($settings['protracktotal']);
    $TMPL['tracksize'] = fsize($settings['tracksize']);
    $TMPL['tracksizetotal'] = fsize($settings['tracksizetotal']);
    $TMPL['promonth'] = $settings['promonth'];
    $TMPL['proyear'] = $settings['proyear'];
    $TMPL['currency'] = $settings['currency'];
    $rows = $skin->make();
    $TMPL = $TMPL_old;
    unset($TMPL_old);
    $TMPL['rows'] = $rows;
    if (isset($_GET['logout']) == 1) {
        $loggedIn->logOut();
        header("Location: " . $CONF['url'] . "/index.php?a=welcome");
    }
    $TMPL['url'] = $CONF['url'];
    $TMPL['title'] = $LNG['go_pro'] . ' - ' . $settings['title'];
    $TMPL['meta_description'] = $settings['title'] . ' ' . $LNG['go_pro'] . ' - ' . $LNG['go_pro_desc'];
    $skin = new skin('pro/content');
    return $skin->make();
}