function server_admin_delete($server_to_delete = NULL) { $server_id = isset($server_to_delete) ? $server_to_delete : func_arg(0); $lilo_mongo = new LiloMongo(); $lilo_mongo->selectDB('Servers'); $lilo_mongo->selectCollection('GameServer'); $lilo_mongo->remove(array('lilo_id' => $server_id)); return '1'; }
function friend_user_ws_deletefromcircle($args = NULL) { if (!isset($args)) { $args = $_REQUEST; } extract($args); if (!isset($friend_id) || !isset($circle_name)) { return 'Data yang Anda kirimkan tidak lengkap'; } if (!isset($user_id)) { $user_id = $_SESSION['user_id']; } // hapus $friend_id dari circle $circle_name // di table Friends untuk user_id = $_SESSION['user_id'] // dapatkan dulu detail dari Friends $lilo_mongo = new LiloMongo(); $lilo_mongo->selectDB('Social'); $lilo_mongo->selectCollection('Friends'); // jika User sudah ada di 'Outer Circle', hapus dari table Friends if (trim($circle_name) == 'Outer Circle') { $lilo_mongo->remove(array('user_id' => $user_id, 'friend_id' => $friend_id)); return "1"; } $friend_data = $lilo_mongo->findOne(array('user_id' => $user_id, 'friend_id' => $friend_id)); $old_friend_data = $friend_data; /* $friend_data = Array ( [user_id] => 4df6e7192cbfd4e6c000fd9b [friend_id] => 4e38df26c1b4ba8c09000001 [circle_array] => Array ( [0] => M-Stars [1] => MU FC ) [approval_time] => 1317191174 [_id] => MongoId Object ( [$id] => 4e82be06c1b4ba6c20000000 ) [lilo_id] => 4e82be06c1b4ba6c20000000 ) */ $friend_data['circle_array'] = array_diff((array) $friend_data['circle_array'], array($circle_name)); $lilo_mongo->update_set(array('user_id' => $user_id, 'friend_id' => $friend_id), array('circle_array' => $friend_data['circle_array'])); return '1'; // return "SEMUA DATA, circle: $circle_name, friend_id: $friend_id" . print_r($friend_data, true) . print_r($old_friend_data, true); // return "User ID Anda: $user_id, Data yang Anda kirim: " . $friend_id . ", " . $circle_name; }
function friend_user_chatalert() { $lilo_mongo = new LiloMongo(); $lilo_mongo->selectDB('Social'); $lilo_mongo->selectCollection("ChatAlert"); $user_id = $_SESSION['user_id']; $sender = $lilo_mongo->command_values(array("distinct" => "ChatAlert", "key" => "sender", "query" => array('receiver' => $user_id))); $count_sender = count($sender); $lilo_mongo->selectDB('Users'); $lilo_mongo->selectCollection("Properties"); for ($idx = 0; $idx < $count_sender; $idx++) { $fullname_idx = $count_sender + $idx; $sender_data = $lilo_mongo->findOne(array('lilo_id' => $sender[$idx])); $sender[$fullname_idx] = $sender_data['fullname']; } $lilo_mongo->selectDB('Social'); $lilo_mongo->selectCollection("ChatAlert"); $lilo_mongo->remove(array('receiver' => $user_id)); return json_encode($sender); }
function user_user_deactivate_account() { // data apa saja yang 'dipindahkan'? // Users.Account, Users.Properties, Users.GroupMember // Social.Friends (user_id dan friend_id) $lilo_mongo = new LiloMongo(); $lilo_mongo->selectDB('Users'); $user_id = $_SESSION['user_id']; // 1. Users.Account $lilo_mongo->selectCollection('Account'); $criteria = array('lilo_id' => $user_id); $backup_account = $lilo_mongo->findOne($criteria); $lilo_mongo->remove($criteria); // 2. Users.Properties $lilo_mongo->selectCollection('Properties'); $criteria = array('lilo_id' => $user_id); $backup_properties = $lilo_mongo->findOne($criteria); $lilo_mongo->remove($criteria); // 3. Users.GroupMember $lilo_mongo->selectCollection('GroupMember'); $criteria = array('user_id' => $user_id); $backup_groupmember = $lilo_mongo->findOne($criteria); $lilo_mongo->remove($criteria); $lilo_mongo->selectDB('Social'); // 4. Social.Friends $lilo_mongo->selectCollection('Friends'); $criteria = array('user_id' => $user_id); $backup_friends = $lilo_mongo->findOne($criteria); $lilo_mongo->remove($criteria); // masukkan ke table Users.DeletedUsers $lilo_mongo->selectDB('Users'); $lilo_mongo->selectCollection('DeletedUsers'); $deletedusers = array('account' => $backup_account, 'properties' => $backup_properties, 'groupmember' => $backup_groupmember, 'friends' => $backup_friends); $lilo_mongo->insert($deletedusers); // Logout current user user_user_logout(); header("Location: " . $_SESSION['basepath']); exit; }
function asset_admin_channel_delete($channel_id = NULL) { $channel_id_ = isset($channel_id) ? $channel_id : func_arg(0); // pastikan channel ini tidak ada yg sedang online $lilo_mongo = new LiloMongo(); $lilo_mongo->selectDB('Assets'); $lilo_mongo->selectCollection('Channel'); $channel = $lilo_mongo->findOne(array('lilo_id' => $channel_id_)); if (intval($channel['current_ccu']) == 0) { $lilo_mongo->remove(array('lilo_id' => $channel_id_)); // update Level.channel_number $level_id = $channel['level_id']; $lilo_mongo->selectCollection('Level'); $level = $lilo_mongo->findOne(array('lilo_id' => $level_id)); $channel_number = $level['channel_number'] - 1; if ($channel_number < 0) { $channel_number = 0; } $lilo_mongo->update_set(array('lilo_id' => $level_id), array('channel_number' => $channel_number)); return "1"; } return "Channel tidak dapat dihapus. Masih ada pemain yang menggunakan channel ini."; }
function message_user_shout_delete($lilo_id = NULL) { if (!isset($lilo_id)) { $lilo_id = func_arg(0); } $user_id = $_SESSION['user_id']; $lilo_mongo = new LiloMongo(); $lilo_mongo->selectDB('Social'); $lilo_mongo->selectCollection('Shout'); $criteria = array('lilo_id' => $lilo_id, 'user_id' => $user_id); //die(print_r($criteria, true)); $lilo_mongo->remove($criteria); // delete all related comments print "1"; exit; }
function asset_admin_category() { $lilo_mongo = new LiloMongo(); $lilo_mongo->selectDB('Assets'); $lilo_mongo->selectCollection('Category'); $op = isset($op) ? $op : func_arg(0); $op = strtolower(trim($op)); switch ($op) { case 'add': $data = array('name' => $_POST['name'], 'tipe' => $_POST['editor_div_type']); $anim_id = $lilo_mongo->insert($data); break; case 'delete': $lilo_mongo->remove(array('_id' => new MongoId($_POST['_id']))); break; case 'detail': $retval = $lilo_mongo->findOne(array('_id' => new MongoId($_POST['_id']))); $resultdetail = array('_id' => $_POST['_id'], 'name' => $retval['name'], 'tipe' => $retval['tipe']); echo json_encode($resultdetail); exit; break; case 'edit': $lilo_mongo->selectCollection('Category'); $retval = $lilo_mongo->findOne(array('_id' => new MongoId($_POST['id']))); $lilo_mongo->selectCollection('Avatar'); $lilo_mongo->update_set(array('category' => $retval['name']), array('category' => $_POST['name'])); $lilo_mongo->selectCollection('Category'); $lilo_mongo->update_set(array('_id' => new MongoId($_POST['id'])), array('name' => $_POST['name'], 'tipe' => $_POST['editor_div_type'])); break; } $brand_data = $lilo_mongo->find(array(), 0, array("tipe" => 1)); if ($_POST['showdt'] != '') { $brand_data = $lilo_mongo->find(array("tipe" => $_POST['showdt']), 0, array("tipe" => 1)); } $returndt = array(); foreach ($brand_data as $result) { $returndt[] = array('_id' => $result['_id'], 'name' => $result['name'], 'tipe' => $result['tipe']); } if (isset($_POST['json'])) { $listtabel = ""; $listtabel .= "<table class='input_form' width='100%'>"; $listtabel .= "<tr>"; $listtabel .= "<th>Name</th>"; $listtabel .= "<th>Avatar Body Part Type</th>"; $listtabel .= "<th>Action</th>"; $listtabel .= "</tr>"; foreach ($brand_data as $dt) { $listtabel .= "<tr>"; $listtabel .= "<td>" . $dt['name'] . "</td>"; $listtabel .= "<td>" . $dt['tipe'] . "</td>"; $listtabel .= "<td>"; $listtabel .= "<button onclick='functionhapus(\"" . $dt['_id'] . "\");'>Delete</button>"; $listtabel .= "<button onclick='functiongetdetail(\"" . $dt['_id'] . "\");'>Edit</button>"; $listtabel .= "</td>"; $listtabel .= "</tr>"; } $listtabel .= "</table>"; echo $listtabel; exit; } $html = ''; $template = new Template(); $template->basepath = $_SESSION['basepath']; $lilo_mongo->selectCollection('AvatarBodyPart'); $listtipe = $lilo_mongo->find(); $template->tipe_array = $listtipe; $template->category_array = $returndt; $html = $template->render("modules/002_asset_management/templates/asset_admin_category.php"); $html = ui_admin_default(NULL, $html); return $html; }
function quest_admin_ws_quest($op = NULL, $id = NULL, $data = NULL) { if (!isset($op)) { $op = func_arg(0) != '' ? func_arg(0) : 'read'; } $lilo_mongo = new LiloMongo(); $lilo_mongo->selectDB('Game'); // Game: DialogStory, Dialog, DialogOption, Quest $lilo_mongo->selectCollection('Quest'); switch ($op) { case 'create': $data = $_POST; // return "<pre>" . print_r($data, true) . "<pre>"; // cek dulu apakah ID yg dimasukkan sudah ada di db $exists = $lilo_mongo->findOne(array('ID' => $data['ID'])); if (count($exists)) { return "Data Quest dengan ID = " . $data['ID'] . " sudah ada di database!"; } $lilo_id = $lilo_mongo->insert($data); $lilo_mongo->update($data, array_merge($data, array('lilo_id' => (string) $lilo_id)), array("multiple" => false)); return "1"; break; case 'update': $data = $_POST; $exists_ = $lilo_mongo->findOne(array('ID' => $data['ID'])); $exist = $exists_['lilo_id'] != $data['lilo_id']; if ($exists) { return "Data Quest dengan ID = " . $data['ID'] . " sudah ada di database! Gunakan ID lain"; } $lilo_mongo->update_set(array('lilo_id' => $data['lilo_id']), $data); return "1"; break; case 'delete': $lilo_id = func_arg(1); $lilo_mongo->remove(array('lilo_id' => $lilo_id)); return "1"; break; // detail == getone == findONe // digunakan unity web player // detail == getone == findONe // digunakan unity web player case 'detail': $ID = func_arg(1); // $result = $lilo_mongo->findOne(array('lilo_id' => $lilo_id)); $result = $lilo_mongo->findOne(array('ID' => $ID)); $result['IsActive'] = strtolower($result['IsActive']) == 'true' ? true : false; $result['IsDone'] = strtolower($result['IsDone']) == 'true' ? true : false; $result['IsReturn'] = strtolower($result['IsReturn']) == 'true' ? true : false; if (count($result)) { // return json_encode($result); unset($result['_id']); unset($result['_id']); unset($result['lilo_id']); unset($result['Energy']); unset($result['Item']); $result['ID'] = intval($result['ID']); $result['RequiredEnergy'] = intval($result['RequiredEnergy']); $result['Requirement'] = intval($result['Requirement']); $result = json_encode($result); return $result; // return str_replace('"', "'", $result); } else { return ''; } // return json_encode($result); break; // digunakan oleh quest editor // digunakan oleh quest editor case 'detail_by_lilo_id': $lilo_id = func_arg(1); $result = $lilo_mongo->findOne(array('lilo_id' => $lilo_id)); if (count($result)) { // return json_encode($result); $result = json_encode($result); return $result; // return str_replace('"', "'", $result); } else { return ''; } break; } // default: read // read == getall == find $quests = array(); $quests_cursor = $lilo_mongo->find(); while ($quest = $quests_cursor->getNext()) { $quests[] = $quest; } // return json_encode($quests); $quests = json_encode($quests); return $quests; // return str_replace('"', "'", $quests); }
function delete_admin($username) { // pastikan orang ini tidak melakukan suicide... :P if (trim($username) == trim($_SESSION['username'])) { return "You stupid bastard.... You can't delete your own account!"; } $lilo_mongo = new LiloMongo(); $lilo_mongo->selectDB('Users'); $lilo_mongo->selectCollection('Admin'); $array_criteria = array('username' => $username); $lilo_mongo->remove($array_criteria); return TRUE; }
function quest_admin_dropplayerinventory() { $lilo_mongo = new LiloMongo(); $lilo_mongo->selectDB('Game'); // Game: DialogStory, Dialog, DialogOption, Quest $lilo_mongo->selectCollection('PlayerInventory'); $lilo_mongo->remove(array()); return 'OK'; }
function mobile_social_likenewsbutton() { $user_email = func_arg(0); $user_id = _get_id_user($user_email); $news_id = func_arg(1); $lilo_mongo = new LiloMongo(); $lilo_mongo->selectDB('Social'); $lilo_mongo->selectCollection('NewsLike'); $parameter = array("user_id" => $user_id, "news_id" => $news_id); $data = $lilo_mongo->findOne($parameter); $output['message'] = "You Like This"; $output['like'] = TRUE; $output['count'] = $lilo_mongo->count(array("news_id" => $news_id)); if ($data) { $output['message'] = "You Unlike This"; $output['like'] = FALSE; $lilo_mongo->remove($parameter); $output['count'] -= 1; } else { $lilo_mongo->insert($parameter); $output['count'] += 1; } return json_encode($output); }
function user_guest_login($uname = NULL, $passwd = NULL) { // bisa diakses lewat web dgn path: /user/user/login/[username/password] // atau dipanggil langsung dgn fungsi user_guest_login('username','password') $username = isset($uname) ? (string) $uname : (string) func_arg(0); $password = isset($passwd) ? (string) $passwd : (string) func_arg(1); if (!isset($username) || trim($username) == '') { $username = $_POST['username']; } if (!isset($password) || trim($password) == '') { $password = $_POST['password']; } // die("$username, $password"); if (strlen(trim($username)) == 0 || strlen(trim($password)) == 0) { unset($_SESSION['session_id']); unset($_SESSION['username']); unset($_SESSION['user_id']); return "0"; } unset($_SESSION['pop_error_msg']); unset($_SESSION['pop_status_msg']); // connect to mongodb using default setting $lilo_mongo = new LiloMongo(); $lilo_mongo->selectDB('Users'); $lilo_mongo->selectCollection('Account'); $user_exists = $lilo_mongo->findOne(array('username' => $username, 'password' => md5($password))); // revisi 04072012: jika username tidak ditemukan, gunakan email if (!is_array($user_exists) || count($user_exists) == 0) { $user_exists = $lilo_mongo->findOne(array('email' => $username, 'password' => md5($password))); $username = $user_exists['username']; } $session_id = $_SESSION['session_id']; $session_username = $_SESSION['username']; // bagaimana jika $session_username berbeda dengan $username? $cur_date = date("Y-m-d H:i:s"); if (is_array($user_exists) && count($user_exists)) { // die("<pre>".print_r($user_exists, true)."</pre>"); if (trim($session_id) == '' || trim($session_username) == '') { $user_id = (string) $user_exists['_id'] . ''; // generate session_id $session_id = md5($cur_date . " - " . $username); $_SESSION['session_id'] = $session_id; $_SESSION['username'] = $username; $_SESSION['user_id'] = $user_id; // simpan di table session // array(session_id, username, time_start, time_end) // untuk mencegah user login di lebih dari satu browser, jika data session utk user_id sudah ada, maka lakukan hanya update // lakukan insert hanya bila data session utk user_id belum ada $lilo_mongo->selectCollection('Session'); $exist_user_id = $lilo_mongo->findOne(array('user_id' => $user_id)); if (is_array($exist_user_id) && count($exist_user_id)) { // $lilo_mongo->update_set( // array( // 'user_id' => $user_id, // ), // array( // 'session_id' => $session_id, //// 'user_id' => $user_id, //// 'username' => $username, //// 'time_start' => $cur_date, //// 'time_end' => '' // ) // ); $lilo_mongo->selectCollection('SessionLog'); $lilo_mongo->insert($exist_user_id); } // else { $lilo_mongo->selectCollection('Session'); $lilo_mongo->remove(array('user_id' => $user_id)); $lilo_mongo->insert(array('session_id' => $session_id, 'user_id' => $user_id, 'username' => $username, 'time_start' => $cur_date, 'time_end' => '', 'HTTP_USER_AGENT' => $_SERVER['HTTP_USER_AGENT'], 'REMOTE_ADDR' => $_SERVER['REMOTE_ADDR'], 'REMOTE_HOST' => $_SERVER['REMOTE_HOST'])); // } report_admin_countuseronlinetime($user_id); return $session_id; } else { // sepertinya kondisi ini tidak akan terpenuhi... :P if ($session_username == $username) { // mencoba login, padahal sudah terdaftar... // biarkan saja, sepertinya orang ini ga ada kerjaan return $session_id; } else { // sudah terdaftar, kemudian mencoba login dengan username dan password yg lain // logout dulu, baru login dengan username yg baru // update($array_criteria, $array_newobj, $array_options) $array_criteria = array('session_id' => $session_id); $array_newobj = array('$set' => array('time_end' => $cur_date)); $array_options = array('upsert' => true); $lilo_mongo->selectCollection('Session'); $lilo_mongo->update($array_criteria, $array_newobj, $array_options); $session_id = md5($cur_date . " - " . $username); $_SESSION['session_id'] = $session_id; $_SESSION['username'] = $username; // simpan di table session // array(session_id, username, time_start, time_end) $lilo_mongo->selectCollection('Session'); $lilo_mongo->insert(array('session_id' => $session_id, 'username' => $username, 'time_start' => $cur_date, 'time_end' => '', 'HTTP_USER_AGENT' => $_SERVER['HTTP_USER_AGENT'], 'REMOTE_ADDR' => $_SERVER['REMOTE_ADDR'], 'REMOTE_HOST' => $_SERVER['REMOTE_HOST'])); return $session_id; } } } else { unset($_SESSION['session_id']); unset($_SESSION['username']); unset($_SESSION['user_id']); return "0"; } }
function article_admin_deleteslide($lilo_id = NULL) { if (!isset($lilo_id)) { $lilo_id = $_POST['lilo_id']; } $lilo_mongo = new LiloMongo(); $lilo_mongo->selectDB('Articles'); $lilo_mongo->selectCollection('Slideshow'); // remove($array_criteria, $array_options = array()) $array_criteria = array('lilo_id' => $lilo_id); $lilo_mongo->remove($array_criteria); return "OK"; }