· 8 years ago · Jun 29, 2017, 12:10 PM
1<?php
2
3class Admin extends BaseController
4{
5
6 function __construct()
7 {
8 $this->put_whois_online();
9 if(Check::is_table("settings"))
10 {
11 Settings::load();
12 }
13 Auth::table("admins");
14 Template::set_as_admin();
15 }
16
17 public function home()
18 {
19 if(Auth::check("admins"))
20 {
21 //online
22 set("all_online", Usersonline::calcul("all"));
23 set("guests_online", Usersonline::calcul("guests"));
24 set("users_online", Usersonline::calcul("users"));
25 set("admins_online", Usersonline::calcul("admins"));
26
27 //count
28 set("users_count", Getdata::howmany("users"));
29 set("admins_count", Getdata::howmany("admins"));
30 set("websites_count", Getdata::howmany("websites"));
31 set("referrals_count", Getdata::howmany("referrals"));
32
33 //hits
34 set("hits_count", floor(Hits::all_hits()));
35 set("points_count", floor(Hits::all_points()));
36
37 $browser = array();
38 $os = array();
39 $browser["UNKNOWN_BROWSER"] = array(floor(Hits::all_hits_by_browser("unknown")), "unknown");
40 $browser["OPERA"] = array(floor(Hits::all_hits_by_browser("Opera")), "Opera");
41 $browser["OPERA_MINI"] = array(floor(Hits::all_hits_by_browser("Opera Mini")), "Opera Mini");
42 $browser["WEBTV"] = array(floor(Hits::all_hits_by_browser("WebTV")), "WebTV");
43 $browser["IE"] = array(floor(Hits::all_hits_by_browser("Internet Explorer")), "Internet Explorer");
44 $browser["EDGE"] = array(floor(Hits::all_hits_by_browser("Microsoft Edge")), "Microsoft Edge");
45 $browser["POCKET_IE"] = array(floor(Hits::all_hits_by_browser("Pocket Internet Explorer")), "Pocket Internet Explorer");
46 $browser["KONQUEROR"] = array(floor(Hits::all_hits_by_browser("Konqueror")), "Konqueror");
47 $browser["ICAB"] = array(floor(Hits::all_hits_by_browser("iCab")), "iCab");
48 $browser["OMNIWEB"] = array(floor(Hits::all_hits_by_browser("OmniWeb")), "OmniWeb");
49 $browser["FIREBIRD"] = array(floor(Hits::all_hits_by_browser("Firebird")), "Firebird");
50 $browser["FIREFOX"] = array(floor(Hits::all_hits_by_browser("Firefox")), "Firefox");
51 $browser["SEAMONKEY"] = array(floor(Hits::all_hits_by_browser("SeaMonkey")), "SeaMonkey");
52 $browser["ICEWEASEL"] = array(floor(Hits::all_hits_by_browser("Iceweasel")), "Iceweasel");
53 $browser["SHIRETOKO"] = array(floor(Hits::all_hits_by_browser("Shiretoko")), "Shiretoko");
54 $browser["MOZILLA"] = array(floor(Hits::all_hits_by_browser("Mozilla")), "Mozilla");
55 $browser["AMAYA"] = array(floor(Hits::all_hits_by_browser("Amaya")), "Amaya");
56 $browser["LYNX"] = array(floor(Hits::all_hits_by_browser("Lynx")), "Lynx");
57 $browser["SAFARI"] = array(floor(Hits::all_hits_by_browser("Safari")), "Safari");
58 $browser["CHROME"] = array(floor(Hits::all_hits_by_browser("Chrome")), "Chrome");
59 $browser["NAVIGATOR"] = array(floor(Hits::all_hits_by_browser("Navigator")), "Navigator");
60 $browser["GOOGLEBOT"] = array(floor(Hits::all_hits_by_browser("GoogleBot")), "GoogleBot");
61 $browser["SLURP"] = array(floor(Hits::all_hits_by_browser("Yahoo! Slurp")), "Yahoo! Slurp");
62 $browser["W3CVALIDATOR"] = array(floor(Hits::all_hits_by_browser("W3C Validator")), "W3C Validator");
63 $browser["BLACKBERRY"] = array(floor(Hits::all_hits_by_browser("BlackBerry")), "BlackBerry");
64 $browser["ICECAT"] = array(floor(Hits::all_hits_by_browser("IceCat")), "IceCat");
65 $browser["NOKIA_S60"] = array(floor(Hits::all_hits_by_browser("Nokia S60 OSS Browser")), "Nokia S60 OSS Browser");
66 $browser["NOKIA"] = array(floor(Hits::all_hits_by_browser("Nokia Browser")), "Nokia Browser");
67 $browser["MSN"] = array(floor(Hits::all_hits_by_browser("MSN Browser")), "MSN Browser");
68 $browser["MSNBOT"] = array(floor(Hits::all_hits_by_browser("MSN Bot")), "MSN Bot");
69 $browser["NETSCAPE_NAVIGATOR"] = array(floor(Hits::all_hits_by_browser("Netscape Navigator")), "Netscape Navigator");
70 $browser["GALEON"] = array(floor(Hits::all_hits_by_browser("Galeon")), "Galeon");
71 $browser["NETPOSITIVE"] = array(floor(Hits::all_hits_by_browser("NetPositive")), "NetPositive");
72 $browser["PHOENIX"] = array(floor(Hits::all_hits_by_browser("Phoenix")), "Phoenix");
73 $browser["GSA"] = array(floor(Hits::all_hits_by_browser("Google Search Appliance")), "Google Search Appliance");
74
75 $os["UNKNOWN_OS"] = array(floor(Hits::all_hits_by_os("unknown")), "unknown");
76 $os["OSX"] = array(floor(Hits::all_hits_by_os("OS X")), "OS X");
77 $os["IOS"] = array(floor(Hits::all_hits_by_os("iOS")), "iOS");
78 $os["SYMBOS"] = array(floor(Hits::all_hits_by_os("SymbOS")), "SymbOS");
79 $os["WINDOWS"] = array(floor(Hits::all_hits_by_os("Windows")), "Windows");
80 $os["ANDROID"] = array(floor(Hits::all_hits_by_os("Android")), "Android");
81 $os["LINUX"] = array(floor(Hits::all_hits_by_os("Linux")), "Linux");
82 $os["NOKIA"] = array(floor(Hits::all_hits_by_os("Nokia")), "Nokia");
83 $os["BLACKBERRY"] = array(floor(Hits::all_hits_by_os("BlackBerry")), "BlackBerry");
84 $os["FREEBSD"] = array(floor(Hits::all_hits_by_os("FreeBSD")), "FreeBSD");
85 $os["OPENBSD"] = array(floor(Hits::all_hits_by_os("OpenBSD")), "OpenBSD");
86 $os["NETBSD"] = array(floor(Hits::all_hits_by_os("NetBSD")), "NetBSD");
87 $os["OPENSOLARIS"] = array(floor(Hits::all_hits_by_os("OpenSolaris")), "OpenSolaris");
88 $os["SUNOS"] = array(floor(Hits::all_hits_by_os("SunOS")), "SunOS");
89 $os["OS2"] = array(floor(Hits::all_hits_by_os("OS2")), "OS2");
90 $os["BEOS"] = array(floor(Hits::all_hits_by_os("BeOS")), "BeOS");
91
92 set("browser", $browser);
93 set("os", $os);
94 set("title2", "Dashboard");
95 Template::view("home");
96 }
97 else
98 {
99 to_router("admin_login");
100 }
101 }
102
103 public function settings()
104 {
105 if(Auth::check("admins"))
106 {
107 $name = Request::post("update_name");
108 $logo = Request::post("update_logo");
109 $language = Request::post("update_language");
110 $template = Request::post("update_template");
111 $admin_template = Request::post("update_admin_template");
112 $currency = Request::post("update_currency");
113 $confirm_referrals = Request::post("update_auto_confirm_referrals");
114 $confirm_websites = Request::post("update_auto_confirm_websites");
115 if($confirm_referrals=="yes"){ $refval = "1"; } else { $refval = "0"; }
116 if($confirm_websites=="yes"){ $webval = "1"; } else { $webval = "0"; }
117 if(!empty($name) || !empty($language))
118 {
119 Settings::set("generale", array(
120 "name" => $name,
121 "logo" => $logo,
122 "language" => $language,
123 "template" => $template,
124 "admin_template" => $admin_template,
125 "currency" => $currency,
126 "auto_confirm_referrals" => $refval,
127 "auto_confirm_websites" => $webval
128 ));
129 define("alert_success", "Well done, Generale settings updated");
130 if(Request::is_ajax())
131 {
132 $this->makejson();
133 }
134 }
135
136 $analyse_code = Request::post("update_google_code");
137 if(!empty($analyse_code))
138 {
139 Settings::set("analyse", array(
140 "code" => $analyse_code
141 ));
142 define("alert_success", "Well done, Analyse code updated");
143 if(Request::is_ajax())
144 {
145 $this->makejson();
146 }
147 }
148
149 $facebook_1 = Request::post("facebook_id");
150 $facebook_2 = Request::post("facebook_secret");
151 $twitter_1 = Request::post("twitter_key");
152 $twitter_2 = Request::post("twitter_secret");
153 $google_1 = Request::post("google_id");
154 $google_2 = Request::post("google_secret");
155 if(!empty($facebook_1) or !empty($facebook_2) or !empty($twitter_1) or !empty($twitter_2) or !empty($google_1) or !empty($google_2))
156 {
157 Settings::set("socialauth", array(
158 "facebook" => array(
159 "id" => $facebook_1,
160 "secret" => $facebook_2
161 ),
162 "twitter" => array(
163 "key" => $twitter_1,
164 "secret" => $twitter_2
165 ),
166 "google" => array(
167 "id" => $google_1,
168 "secret" => $google_2
169 )
170 ));
171 define("alert_success", "Well done, Social Authentication updated");
172 if(Request::is_ajax())
173 {
174 $this->makejson();
175 }
176 }
177
178 $seo_title = Request::post("seo_title");
179 $seo_description = Request::post("seo_description");
180 $seo_keywords = Request::post("seo_keywords");
181 $seo_ogimage = Request::post("seo_ogimage");
182 $seo_favicon = Request::post("seo_favicon");
183 if(!empty($seo_title) or !empty($seo_description) or !empty($seo_keywords) or !empty($seo_ogimage) or !empty($seo_favicon))
184 {
185 Settings::set("seo", array(
186 "title" => $seo_title,
187 "description" => $seo_description,
188 "keywords" => $seo_keywords,
189 "ogimage" => $seo_ogimage,
190 "favicon" => $seo_favicon
191 ));
192 define("alert_success", "Well done, SEO settings updated");
193 if(Request::is_ajax())
194 {
195 $this->makejson();
196 }
197 }
198
199 $ads_header = Request::post("ads_header");
200 $ads_footer = Request::post("ads_footer");
201 if(!empty($ads_footer) or !empty($ads_header))
202 {
203 Settings::set("ads", array(
204 "header" => $ads_header,
205 "footer" => $ads_footer
206 ));
207 define("alert_success", "Well done, Ads settings updated");
208 if(Request::is_ajax())
209 {
210 $this->makejson();
211 }
212 }
213
214 $blacklist = Request::post("update_backlist");
215 $whitelist = Request::post("update_whitelist");
216 if(!empty($blacklist) || !empty($whitelist))
217 {
218 $new_blacklist = array();
219 $new_whitelist = array();
220 if($blacklist)
221 {
222 $black = explode("\n", $blacklist);
223 if(!empty($black) && is_array($black))
224 {
225 foreach($black as $bl)
226 {
227 $bl = trim($bl);
228 $newbl = str_replace(array("www.", "http://", "https://"), "", $bl);
229 $host = explode("/", $newbl);
230 $new_blacklist[] = $host[0];
231 }
232 }
233 }
234 if($whitelist)
235 {
236 $white = explode("\n", $whitelist);
237 if(!empty($white) && is_array($white))
238 {
239 foreach($white as $wh)
240 {
241 $wh = trim($wh);
242 $newwh = str_replace(array("www.", "http://", "https://", " "), "", $wh);
243 $host = explode("/", $newwh);
244 $new_whitelist[] = $host[0];
245 }
246 }
247 }
248 Settings::set("blacklist", array("lists" => $new_blacklist));
249 Settings::set("whitelist", array("lists" => $new_whitelist));
250 define("alert_success", "Well done, the lists are Updated");
251 if(Request::is_ajax())
252 {
253 $this->makejson();
254 }
255 }
256
257 $exchange_openmode = Request::post("update_exchange_openmode");
258 $exchange_minduration = Request::post("update_exchange_minduration");
259 $exchange_focus = Request::post("update_exchange_focus");
260 $exchange_maxduration = Request::post("update_exchange_maxduration");
261 //$exchange_source = Request::post("update_exchange_source");
262 $exchange_pointcost = Request::post("update_exchange_pointcost");
263
264 if(!empty($exchange_minduration) || !empty($exchange_maxduration))
265 {
266 Settings::set("exchange", array(
267 "openmode" => $exchange_openmode,
268 "focus" => $exchange_focus,
269 "minduration" => $exchange_minduration,
270 "maxduration" => $exchange_maxduration,
271 //"source" => $exchange_source,
272 "pointcost" => $exchange_pointcost
273 ));
274 define("alert_success", "Well done, Exchange settings updated");
275 if(Request::is_ajax())
276 {
277 $this->makejson();
278 }
279 }
280
281 $allowed_countries = Request::post("allowed_countries");
282 $access_geo = Request::post("access_geo");
283 if(!empty($allowed_countries))
284 {
285 if(is_array($allowed_countries))
286 {
287 $countries = array();
288 $getting_countries = json_decode(BaseModel::$country_list, true);
289 foreach($allowed_countries as $country)
290 {
291 $countries[$country] = $getting_countries[$country];
292 }
293 Settings::set("geotarget", array("list" => $countries, "access" => $access_geo));
294 define("alert_success", "Well done, Geo Targetting settings updated");
295 if(Request::is_ajax())
296 {
297 $this->makejson();
298 }
299 }
300 }
301
302 $stripe_mode = Request::post("update_stripe_mode");
303 $stripe_pubkey = Request::post("update_stripe_publickey");
304 $stripe_seckey = Request::post("update_stripe_secretkey");
305 $paypal_mode = Request::post("update_paypal_mode");
306 $paypal_username = Request::post("update_paypal_username");
307 $paypal_password = Request::post("update_paypal_password");
308 $paypal_signature = Request::post("update_paypal_signature");
309 $payza_mode = Request::post("update_payza_mode");
310 $payza_email = Request::post("update_payza_email");
311 if(!empty($paypal_mode) || !empty($payza_mode))
312 {
313 Settings::set("payments", array(
314 "paypal" => array(
315 "mode" => $paypal_mode,
316 "username" => $paypal_username,
317 "password" => $paypal_password,
318 "signature" => $paypal_signature
319 ),
320 "payza" => array(
321 "mode" => $payza_mode,
322 "email" => $payza_email
323 ),
324 "stripe" => array(
325 "mode" => $stripe_mode,
326 "public_key" => $stripe_pubkey,
327 "secret_key" => $stripe_seckey
328 )
329 ));
330 define("alert_success", "Well done, Payment settings updated");
331 if(Request::is_ajax())
332 {
333 $this->makejson();
334 }
335 }
336 $email = Request::post("update_email");
337 $email_confirm = Request::post("update_email_confirmation");
338 $mail_type = Request::post("update_mail_type");
339 $smtp_host = Request::post("update_smtp_host");
340 $smtp_port = Request::post("update_smtp_port");
341 $smtp_auth = Request::post("update_smtp_auth");
342 $smtp_username = Request::post("update_smtp_username");
343 $smtp_password = Request::post("update_smtp_password");
344 if($email_confirm == "yes") { $confr = "1"; } else { $confr = "0"; }
345 if($smtp_auth=="yes"){ $smtp_auth = "1"; } else { $smtp_auth = "0"; }
346 if(!empty($mail_type) || !empty($email))
347 {
348 Settings::set("mail", array(
349 "type" => $mail_type,
350 "from" => $email,
351 "activation" => $confr,
352 "smtp" => array(
353 "host" => $smtp_host,
354 "port" => $smtp_port,
355 "secure" => "tls",
356 "auth" => $smtp_auth,
357 "username" => $smtp_username,
358 "password" => $smtp_password
359 )
360 ));
361 define("alert_success", "Well done, Mail settings updated");
362 if(Request::is_ajax())
363 {
364 $this->makejson();
365 }
366 }
367 $website_slots = Request::post("update_website_slots", "i");
368 $session_slots = Request::post("update_session_slots", "i");
369 $traffic_ratio = Request::post("update_traffic_ratio", "i");
370 $points = Request::post("update_points", "i");
371 $referrals_points = Request::post("update_referrals_points");
372 $default_url = Request::post("update_default_url");
373 $default_withdrawal_status = Request::post("update_referrals_withdrawal_status");
374 $default_min_withdrawal = Request::post("update_referrals_minwithdrawal");
375 if(!empty($website_slots) || !empty($session_slots))
376 {
377 Settings::set("defaults", array(
378 "withdrawal_status" => $default_withdrawal_status,
379 "min_for_withdrawal" => $default_min_withdrawal,
380 "website_slots" => $website_slots,
381 "session_slots" => $session_slots,
382 "traffic_ratio" => $traffic_ratio,
383 "points" => $points,
384 "referrals_points" => $referrals_points,
385 "website" => $default_url
386 ));
387 define("alert_success", "Well done, Default values updated");
388 if(Request::is_ajax())
389 {
390 $this->makejson();
391 }
392 }
393 $recaptcha_publickey = Request::post("update_recaptcha_publickey");
394 $recaptcha_privatekey = Request::post("update_recaptcha_privatekey");
395 if(!empty($recaptcha_publickey) || !empty($recaptcha_privatekey))
396 {
397 Settings::set("recaptcha", array(
398 "publickey" => $recaptcha_publickey,
399 "privatekey" => $recaptcha_privatekey
400 ));
401 define("alert_success", "Well done, Recaptcha settings updated");
402 if(Request::is_ajax())
403 {
404 $this->makejson();
405 }
406 }
407 $facebook = Request::post("update_facebook");
408 $twitter = Request::post("update_twitter");
409 $google_plus = Request::post("update_google_plus");
410 $pinterest = Request::post("update_pinterest");
411 $instagram = Request::post("update_instagram");
412 $dribbble = Request::post("update_dribbble");
413 if(!empty($facebook) || !empty($twitter) || !empty($google_plus) || !empty($pinterest) || !empty($instagram) || !empty($dribbble))
414 {
415 Settings::set("social", array(
416 "facebook" => $facebook,
417 "twitter" => $twitter,
418 "google_plus" => $google_plus,
419 "pinterest" => $pinterest,
420 "instagram" => $instagram,
421 "dribbble" => $dribbble
422 ));
423 define("alert_success", "Well done, Social settings updated");
424 if(Request::is_ajax())
425 {
426 $this->makejson();
427 }
428 }
429 $get_templates = glob("themes/user/*", GLOB_ONLYDIR);
430 $get_admin_templates = glob("themes/admin/*", GLOB_ONLYDIR);
431 $get_languages = Languages::info();
432 $currency = s("currency");
433 if(!empty($get_languages))
434 {
435 foreach($get_languages as $language)
436 {
437 $languages[$language["code"]] = $language["name"];
438 }
439 }
440 if(!empty($get_templates))
441 {
442 foreach($get_templates as $template)
443 {
444 $tmpl = str_replace("themes/user/", "", $template);
445 $templates[$tmpl] = $tmpl;
446 }
447 }
448 if(!empty($get_admin_templates))
449 {
450 foreach($get_admin_templates as $admin_template)
451 {
452 $tmpl = str_replace("themes/admin/", "", $admin_template);
453 $admin_templates[$tmpl] = $tmpl;
454 }
455 }
456 set("templates", $templates);
457 set("admin_templates", $admin_templates);
458 set("languages", $languages);
459 set("currency", $currency);
460 set("title2", "Settings");
461 Template::view("edit_settings");
462 }
463 else
464 {
465 to_router("admin_login");
466 }
467 }
468
469
470 public function users()
471 {
472 if(Auth::check("admins"))
473 {
474 $edit = strip_tags(Request::get("edit", "i"));
475 if(!empty($edit))
476 {
477 $getone = Getdata::one_user($edit);
478 if(!empty($getone))
479 {
480 set("info", $getone);
481 set("title2", "Edit");
482 }
483 else
484 {
485 to_router("admin_users");
486 }
487 }
488 else
489 {
490 $pag = Pagination::build(router("admin_users"), "users", 30);
491 $getdata = Getdata::users($pag[0], $pag[1]);
492 set("users", $getdata);
493 set("pagination", $pag[2]);
494 set("title2", "Users");
495 }
496 Template::view("users");
497 }
498 else
499 {
500 to_router("admin_login");
501 }
502 }
503
504 public function search()
505 {
506 if(Auth::check("admins"))
507 {
508 $search = strip_tags(Request::get("q"));
509 $kind = strtolower(strip_tags(Request::get("kind", "a")));
510 if(!empty($search) && !empty($kind))
511 {
512 $tables = array(
513 "users",
514 "websites",
515 "payments",
516 "plans",
517 "newsletteres"
518 );
519 if(in_array($kind, $tables))
520 {
521 $query_url = "?q=".$search."&kind=".$kind;
522 switch($kind)
523 {
524 case 'users':
525 $pag = Pagination::build(router("admin_search").$query_url, array(
526 "query" => "users WHERE id LIKE :id or username LIKE :username or email LIKE :email or type LIKE :type",
527 "binds" => array(
528 "id" => "%".$search."%",
529 "username" => "%".$search."%",
530 "email" => "%".$search."%",
531 "type" => "%".$search."%"
532 )
533 ), 30, 2, "&p=");
534 break;
535 case 'websites':
536 $pag = Pagination::build(router("admin_search").$query_url, array(
537 "query" => "websites WHERE id LIKE :id or user_id LIKE :userid or url LIKE :url or geolocation LIKE :geolocation",
538 "binds" => array(
539 "id" => "%".$search."%",
540 "userid" => "%".$search."%",
541 "url" => "%".$search."%",
542 "geolocation" => "%".$search."%"
543 )
544 ), 30, 2, "&p=");
545 break;
546 case 'payments':
547 $pag = Pagination::build(router("admin_search").$query_url, array(
548 "query" => "payments WHERE id LIKE :id or payment_id LIKE :paymentid or amount LIKE :amount or payment_service LIKE :paymentservice or currency LIKE :currency",
549 "binds" => array(
550 "id" => "%".$search."%",
551 "paymentid" => "%".$search."%",
552 "amount" => "%".$search."%",
553 "paymentservice" => "%".$search."%",
554 "currency" => "%".$search."%"
555 )
556 ), 30, 2, "&p=");
557 break;
558 case 'plans':
559 $pag = Pagination::build(router("admin_search").$query_url, array(
560 "query" => "plans WHERE id LIKE :id or name LIKE :name or price LIKE :price or type LIKE :type or currency LIKE :currency",
561 "binds" => array(
562 "id" => "%".$search."%",
563 "name" => "%".$search."%",
564 "price" => "%".$search."%",
565 "currency" => "%".$search."%",
566 "type" => "%".$search."%"
567 )
568 ), 30, 2, "&p=");
569 break;
570 case 'newsletteres':
571 $pag = Pagination::build(router("admin_search").$query_url, array(
572 "query" => "newsletteres WHERE id LIKE :id or name LIKE :name or subject LIKE :subject or to_group LIKE :togroup",
573 "binds" => array(
574 "id" => "%".$search."%",
575 "name" => "%".$search."%",
576 "subject" => "%".$search."%",
577 "togroup" => "%".$search."%"
578 )
579 ), 30, 2, "&p=");
580 break;
581 }
582 $getdata = Getdata::admin_search($search, $kind, $pag[0], $pag[1]);
583 set($kind, $getdata);
584 set("pagination", $pag[2]);
585 }
586 }
587 set("title2", "Search");
588 Template::view("search");
589 }
590 else
591 {
592 to_router("admin_login");
593 }
594 }
595
596 public function payments()
597 {
598 if(Auth::check("admins"))
599 {
600 $edit = strip_tags(Request::get("edit", "i"));
601 if(!empty($edit))
602 {
603 $getone = Getdata::one_payment($edit);
604 if(!empty($getone))
605 {
606 set("info", $getone);
607 set("title2", "Edit");
608 }
609 else
610 {
611 to_router("admin_payments");
612 }
613 }
614 else
615 {
616 $pag = Pagination::build(router("admin_payments"), "payments", 30);
617 $getdata = Getdata::payments($pag[0], $pag[1]);
618 set("payments", $getdata);
619 set("pagination", $pag[2]);
620 set("title2", "Payments");
621 }
622 Template::view("payments");
623 }
624 else
625 {
626 to_router("admin_login");
627 }
628 }
629
630 public function withdrawals()
631 {
632 if(Auth::check("admins"))
633 {
634 $edit = strip_tags(Request::get("show", "i"));
635 $delete = strip_tags(Request::get("done", "i"));
636 if(!empty($edit))
637 {
638 Db::bind("uid", strip_tags($edit));
639 $getone = Db::query("SELECT * FROM affiliate WHERE user_id = :uid");
640 if(!empty($getone[0]))
641 {
642 set("info", $getone[0]);
643 set("title2", "Edit");
644 }
645 else
646 {
647 to_router("admin_withdrawals");
648 }
649 }
650 else if(!empty($delete))
651 {
652 Db::bind("uid", strip_tags($delete));
653 $getone = Db::query("SELECT * FROM wallet WHERE user_id = :uid");
654 if(!empty($getone[0]))
655 {
656 Wallet::empty_sold("withdrawal", $getone[0]["user_id"]);
657 }
658 to_router("admin_withdrawals");
659 }
660 else
661 {
662 $pag = Pagination::build(router("admin_withdrawals"), "wallet WHERE withdrawal_sold > 0", 30);
663 $getdata = Getdata::withdrawals($pag[0], $pag[1]);
664 set("withdrawals", $getdata);
665 set("pagination", $pag[2]);
666 set("title2", "Withdrawals");
667 }
668 Template::view("withdrawals");
669 }
670 else
671 {
672 to_router("admin_login");
673 }
674 }
675
676 public function currencies()
677 {
678 if(Auth::check("admins"))
679 {
680 $kind = Request::get("kind");
681 if($kind=="add")
682 {
683 $code = Request::post("currency_code");
684 $name = Request::post("currency_name");
685 $value = Request::post("currency_value");
686 if(!empty($code) && !empty($name) && !empty($value))
687 {
688 USD_Convert::add($code, $name, $value);
689 define("alert_success", "Added");
690 if(Request::is_ajax())
691 {
692 $this->makejson();
693 }
694 else
695 {
696 to_router("admin_currencies");
697 }
698 }
699 }
700 else if($kind=="update")
701 {
702 $code = Request::post("currency_code");
703 $name = Request::post("currency_name");
704 $value = Request::post("currency_value");
705 if(!empty($code) && !empty($name) && !empty($value))
706 {
707 USD_Convert::update($code, $name, $value);
708 define("alert_success", "Updated");
709 if(Request::is_ajax())
710 {
711 $this->makejson();
712 }
713 else
714 {
715 to_router("admin_currencies");
716 }
717 }
718 }
719 else if($kind=="remove")
720 {
721 $code = Request::post("currency_code");
722 if(!empty($code))
723 {
724 USD_Convert::remove($code);
725 define("alert_success", "Removed");
726 if(Request::is_ajax())
727 {
728 $this->makejson();
729 }
730 else
731 {
732 to_router("admin_currencies");
733 }
734 }
735 }
736 set("currencies", s("currency"));
737 set("usd_convert", s("usd_convert"));
738 set("title2", "Currency control");
739 Template::view("currencies");
740 }
741 else
742 {
743 to_router("admin_login");
744 }
745 }
746
747 public function plans()
748 {
749 if(Auth::check("admins"))
750 {
751 $edit = strip_tags(Request::get("edit", "i"));
752 if(!empty($edit))
753 {
754 $getone = Getdata::one_plan($edit);
755 if(!empty($getone))
756 {
757 set("info", $getone);
758 set("title2", "Edit");
759 }
760 else
761 {
762 to_router("admin_plans");
763 }
764 }
765 else
766 {
767 $pag = Pagination::build(router("admin_plans"), "plans", 30);
768 $getdata = Getdata::plans($pag[0], $pag[1]);
769 set("plans", $getdata);
770 set("pagination", $pag[2]);
771 set("title2", "Plans");
772 }
773 Template::view("plans");
774 }
775 else
776 {
777 to_router("admin_login");
778 }
779 }
780
781 public function referrals()
782 {
783 if(Auth::check("admins"))
784 {
785 $edit = strip_tags(Request::get("edit", "i"));
786 if(!empty($edit))
787 {
788 $getone = Getdata::one_referral($edit);
789 if(!empty($getone))
790 {
791 set("info", $getone);
792 set("title2", "Edit");
793 }
794 else
795 {
796 to_router("admin_referrals");
797 }
798 }
799 else
800 {
801 $pag = Pagination::build(router("admin_referrals"), "referrals", 30);
802 $getdata = Getdata::referrals($pag[0], $pag[1]);
803 set("referrals", $getdata);
804 set("pagination", $pag[2]);
805 set("title2", "Referrals");
806 }
807 Template::view("referrals");
808 }
809 else
810 {
811 to_router("admin_login");
812 }
813 }
814
815 public function admins()
816 {
817 if(Auth::check("admins"))
818 {
819 $edit = strip_tags(Request::get("edit", "i"));
820 if(!empty($edit))
821 {
822 $getone = Getdata::one_admin($edit);
823 if(!empty($getone))
824 {
825 set("info", $getone);
826 set("title2", "Edit");
827 }
828 else
829 {
830 to_router("admin_admins");
831 }
832 }
833 else
834 {
835 $pag = Pagination::build(router("admin_admins"), "admins", 30);
836 $getdata = Getdata::admins($pag[0], $pag[1]);
837 set("admins", $getdata);
838 set("pagination", $pag[2]);
839 set("title2", "Admins");
840 }
841 Template::view("admins");
842 }
843 else
844 {
845 to_router("admin_login");
846 }
847 }
848
849 public function account()
850 {
851 if(Auth::check("admins"))
852 {
853 header("location: ".router("admin_admins")."?edit=".u("id"));
854 }
855 else
856 {
857 to_router("admin_login");
858 }
859 }
860
861 public function pages()
862 {
863 if(Auth::check("admins"))
864 {
865 $privacy = Request::post("update_privacy");
866 $about_us = Request::post("update_about_us");
867 $tos = Request::post("update_tos");
868 if(isset($privacy) or isset($about_us) or isset($tos))
869 {
870 $new_pages = array(
871 "privacy" => htmlentities($privacy),
872 "about-us" => htmlentities($about_us),
873 "tos" => htmlentities($tos)
874 );
875 Db::bind("id", 10);
876 Db::bind("newpages", serialize($new_pages));
877 $query = "UPDATE settings SET `option_value` = :newpages WHERE id = :id";
878 if(Db::query($query))
879 {
880 define("alert_success", "Well done - all pages updated.");
881 }
882 else
883 {
884 define("alert_warning", "There is no Changes");
885 }
886 if(Request::is_ajax())
887 {
888 $this->makejson();
889 }
890 }
891 set("title2", "Pages");
892 Template::view("pages");
893 }
894 else
895 {
896 to_router("admin_login");
897 }
898 }
899
900 public function last_websites()
901 {
902 if(Auth::check("admins"))
903 {
904 $pag = Pagination::build(router("admin_last_websites"), "websites WHERE activated = '0'", 30);
905 $getdata = Getdata::unconfirmed_websites($id, $pag[0], $pag[1]);
906 set("websites", $getdata);
907 set("pagination", $pag[2]);
908 set("title2", "Last Websites need confirmation");
909 Template::view("last_websites");
910 }
911 else
912 {
913 to_router("admin_login");
914 }
915 }
916
917 public function websites($match="")
918 {
919 if(Auth::check("admins"))
920 {
921 $id = strip_tags($match["params"]["id"]);
922 if(!empty($id))
923 {
924 set("user_id", $id);
925 $edit = strip_tags(Request::get("edit", "i"));
926 if(!empty($edit))
927 {
928 $getone = Getdata::one_website($edit);
929 if(!empty($getone))
930 {
931 set("info", $getone);
932 set("title2", "Edit");
933 }
934 else
935 {
936 to_router("admin_websites", array("id" => get("user_id")));
937 }
938 }
939 else
940 {
941 $pag = Pagination::build(router("admin_websites", array("id" => get("user_id"))), "websites WHERE user_id = '".$id."'", 30);
942 $getdata = Getdata::user_websites($id, $pag[0], $pag[1]);
943 set("websites", $getdata);
944 set("pagination", $pag[2]);
945 set("title2", "Websites");
946 }
947 Template::view("websites");
948 }
949 else
950 {
951 to_router("admin_home");
952 }
953 }
954 else
955 {
956 to_router("admin_login");
957 }
958 }
959
960 public function support()
961 {
962 if(Auth::check("admins"))
963 {
964 set("title2", "Support");
965 Template::view("support");
966 }
967 else
968 {
969 to_router("admin_login");
970 }
971 }
972
973 public function generate_time($time)
974 {
975 $extime = explode(",", $time);
976 $newextime = explode(":", $extime[0]);
977 $hour = $newextime[0]; if(empty($hour) or !is_numeric($hour) or $hour > 24){ $hour = date("h"); }
978 $min = $newextime[1]; if(empty($min) or !is_numeric($min) or $min > 60){ $min = date("i"); }
979 $day = $extime[1]; if(empty($day) or !is_numeric($day) or $day > 31){ $day = date("d"); }
980 $month = $extime[2]; if(empty($month) or !is_numeric($month) or $month > 12){ $month = date("m"); }
981 $year = $extime[3]; if(empty($year) or !is_numeric($year) or $year < date("Y")){ $year = date("Y"); }
982 return mktime($hour, $min, 0, $month, $day, $year);
983 }
984
985 public function newsletteres($match="")
986 {
987 if(Auth::check("admins"))
988 {
989 $edit = strip_tags(Request::get("edit", "i"));
990 $type = strip_tags(Request::post("kindofpost"));
991 $name = strip_tags(Request::post("name"));
992 $to_group = strip_tags(Request::post("to_group"));
993 $subject = strip_tags(Request::post("subject"));
994 $content = Request::post("content");
995 $starton = strip_tags(Request::post("starton"));
996 if(Request::is_post())
997 {
998 if($type == "server_settings")
999 {
1000 $email = Request::post("email");
1001 $email_replyto = Request::post("email_replyto");
1002 $mail_type = Request::post("mail_type");
1003 $smtp_host = Request::post("smtp_host");
1004 $smtp_port = Request::post("smtp_port");
1005 $smtp_secure = Request::post("smtp_secure");
1006 $smtp_auth = Request::post("smtp_auth");
1007 $smtp_username = Request::post("smtp_username");
1008 $smtp_password = Request::post("smtp_password");
1009 $max_per_cron = Request::post("max_per_cron");
1010 if($smtp_auth=="yes"){ $smtp_auth = "1"; } else { $smtp_auth = "0"; }
1011 if(!is_numeric($max_per_cron)) { $max_per_cron = 20; }
1012 if(!empty($mail_type) || !empty($email))
1013 {
1014 Settings::set("newsletteres", array(
1015 "type" => $mail_type,
1016 "from" => $email,
1017 "replyto" => $email_replyto,
1018 "max" => $max_per_cron,
1019 "smtp" => array(
1020 "host" => $smtp_host,
1021 "port" => $smtp_port,
1022 "secure" => $smtp_secure,//tls -- ssl
1023 "auth" => $smtp_auth,
1024 "username" => $smtp_username,
1025 "password" => $smtp_password
1026 )
1027 ));
1028 define("alert_success", "Well done, Server settings updated");
1029 }
1030 else
1031 {
1032 define("alert_error", "Please complete the form");
1033 }
1034 $this->makejson();
1035 }
1036 }
1037 if(Request::is_post())
1038 {
1039 if($type == "add_newsletter")
1040 {
1041 $time = $this->generate_time($starton);
1042 if(!empty($name) && !empty($to_group) && !empty($subject) && !empty($content) && !empty($starton))
1043 {
1044 Db::bind("name", $name);
1045 Db::bind("group", $to_group);
1046 Db::bind("subject", $subject);
1047 Db::bind("content", $content);
1048 Db::bind("time", $time);
1049 Db::bind("progress", "0");
1050 Db::bind("cat", time());
1051 Db::bind("uat", time());
1052 $ex = Db::query("INSERT INTO `newsletteres` (`status`, `name`, `to_group`, `subject`, `content`, `starton`, `progress`, `offset`, `created_at`, `updated_at`) VALUES ('1', :name, :group, :subject, :content, :time, :progress, '0', :cat, :uat);");
1053 if($ex)
1054 {
1055 define("alert_success", "Success, Mail added !!");
1056 }
1057 else
1058 {
1059 define("alert_error", "something went wrong, Please try again");
1060 }
1061 }
1062 else
1063 {
1064 define("alert_error", "Please complete the form");
1065 }
1066 $this->makejson();
1067 }
1068 }
1069
1070 if(!empty($edit))
1071 {
1072 $getone = Getdata::one_newsletter($edit);
1073 if(!empty($getone))
1074 {
1075 if($type == "update_newsletter")
1076 {
1077 $time = $this->generate_time($starton);
1078 if(!empty($name) && !empty($to_group) && !empty($subject) && !empty($content) && !empty($starton))
1079 {
1080 $startover = Request::post("startover");
1081 Db::bind("name", $name);
1082 Db::bind("group", $to_group);
1083 Db::bind("subject", $subject);
1084 Db::bind("content", $content);
1085 Db::bind("time", $time);
1086
1087 if($startover == "On")
1088 {
1089 Db::bind("progress", "0");
1090 Db::bind("offset", "0");
1091 }
1092 else
1093 {
1094 Db::bind("progress", $getone["progress"]);
1095 Db::bind("offset", $getone["offset"]);
1096 }
1097
1098 Db::bind("id", $getone["id"]);
1099 Db::bind("uat", time());
1100 $ex = Db::query("UPDATE `newsletteres` SET `name` = :name, `to_group` = :group, `subject` = :subject, `content` = :content, `starton` = :time, `progress` = :progress, `offset` = :offset, `updated_at` = :uat WHERE id = :id");
1101 if($ex)
1102 {
1103 define("alert_success", "Success, Mail Updated !!");
1104 }
1105 else
1106 {
1107 define("alert_error", "something went wrong, Please try again");
1108 }
1109 }
1110 else
1111 {
1112 define("alert_error", "Please complete the form");
1113 }
1114 $this->makejson();
1115 }
1116 set("info", $getone);
1117 set("title2", "Edit");
1118 }
1119 else
1120 {
1121 to_router("admin_newsletteres");
1122 }
1123 }
1124 else
1125 {
1126 $pag = Pagination::build(router("admin_newsletteres"), "newsletteres", 30);
1127 $getdata = Getdata::newsletteres($pag[0], $pag[1]);
1128 set("newsletteres", $getdata);
1129 set("pagination", $pag[2]);
1130 set("title2", "Newsletteres");
1131 }
1132 Template::view("newsletteres");
1133 }
1134 else
1135 {
1136 to_router("admin_login");
1137 }
1138 }
1139
1140 public function logout()
1141 {
1142 Auth::logout();
1143 to_router("admin_login");
1144 }
1145
1146 public function double_number($number)
1147 {
1148 $ex = explode(".", $number);
1149 if(!empty($ex[0]) && !empty($ex[1]))
1150 {
1151 return $number;
1152 }
1153 else if(!empty($ex[0]) && empty($ex[1]))
1154 {
1155 return $ex[0].".00";
1156 }
1157 else if(empty($ex[0]) && !empty($ex[1]))
1158 {
1159 return "0.".$ex[1];
1160 }
1161 else
1162 {
1163 return "0.00";
1164 }
1165 }
1166
1167 public function ajax_delete()
1168 {
1169 if(Auth::check("admins") && Check::this_referer())
1170 {
1171 $tables = array("admins", "exchange", "hits", "payments", "plans", "referrals", "users", "websites", "newsletteres");
1172 $table = strip_tags(Request::post("del", "a"));
1173 $id = strip_tags(Request::post("id", "i"));
1174 if(!empty($table) && !empty($id))
1175 {
1176 if(in_array($table, $tables))
1177 {
1178 Db::bind("id", $id);
1179 $query = "DELETE FROM ".$table." WHERE id = :id";
1180 if(Db::query($query))
1181 {
1182 define("alert_success", "Deleted");
1183 }
1184 else
1185 {
1186 define("alert_error", "Delete Faild");
1187 }
1188 }
1189 else
1190 {
1191 define("alert_error", "wrong table");
1192 }
1193 }
1194 else
1195 {
1196 define("alert_error", "empty data");
1197 }
1198 }
1199 $this->makejson();
1200 }
1201
1202 public function upgrade_user($match="")
1203 {
1204 if(Auth::check("admins") && Check::this_referer())
1205 {
1206 $uid = strip_tags(Request::post("user_id"));
1207 $dur = strip_tags(Request::post("duration"));
1208 $durtype = strip_tags(Request::post("durtype"));
1209 $time = Upgrade::export_time($dur."-".$durtype);
1210 $get_user = Getdata::one_user($uid);
1211 if(!empty($get_user) && is_array($get_user) && $get_user["type"] != "pro")
1212 {
1213 $query = "UPDATE users SET `type` = :newtype, `pro_exp` = :exp WHERE id = :uid";
1214 Db::bind("newtype", "pro");
1215 Db::bind("exp", $time);
1216 Db::bind("uid", $get_user["id"]);
1217 Db::query($query);
1218 define("alert_success", "Downgrade Account");
1219 }
1220 else if($get_user["type"] == "pro")
1221 {
1222 $query = "UPDATE users SET `type` = :newtype, `pro_exp` = :exp WHERE id = :uid";
1223 Db::bind("newtype", "free");
1224 Db::bind("exp", time()-2);
1225 Db::bind("uid", $get_user["id"]);
1226 Db::query($query);
1227 define("alert_success", "Upgrade Account");
1228 }
1229 else
1230 {
1231 define("alert_error", "Something went wrong, Please Try again !!");
1232 }
1233 }
1234 else
1235 {
1236 define("alert_error", "You need to login first !!");
1237 }
1238 $this->makejson();
1239 }
1240
1241 public function ajax_status($match="")
1242 {
1243 if(Auth::check("admins") && Check::this_referer())
1244 {
1245 $tables = array("admins", "exchange", "hits", "payments", "plans", "referrals", "users", "websites", "newsletteres");
1246 $table = strip_tags(Request::post("set", "a"));
1247 $id = strip_tags(Request::post("id", "i"));
1248 if(!empty($table) && !empty($id))
1249 {
1250 if(in_array($table, $tables))
1251 {
1252 Db::bind("id", $id);
1253 $old = Db::query("SELECT * FROM ".$table." WHERE id = :id");
1254 $old = $old[0];
1255 if(!empty($old))
1256 {
1257 $query = "UPDATE ".$table." SET `status` = :newstatus WHERE id = :itemid";
1258 Db::bind("itemid", $old["id"]);
1259 if($old["status"]=="0")
1260 {
1261 Db::bind("newstatus", "1");
1262 $st = "Disable";
1263 }
1264 else
1265 {
1266 Db::bind("newstatus", "0");
1267 $st = "Enable";
1268 }
1269 if(Db::query($query))
1270 {
1271 define("alert_success", $st);
1272 }
1273 else
1274 {
1275 define("alert_error", "Update Faild");
1276 }
1277 }
1278 else
1279 {
1280 define("alert_error", "wrong data");
1281 }
1282 }
1283 else
1284 {
1285 define("alert_error", "wrong table");
1286 }
1287 }
1288 else
1289 {
1290 define("alert_error", "empty data");
1291 }
1292 }
1293 $this->makejson();
1294 }
1295
1296 public function ajax_confirm($match="")
1297 {
1298 if(Auth::check("admins") && Check::this_referer())
1299 {
1300 $tables = array("payments", "referrals", "websites");
1301 $table = strip_tags(Request::post("set", "a"));
1302 $id = strip_tags(Request::post("id", "i"));
1303 if(!empty($table) && !empty($id))
1304 {
1305 if(in_array($table, $tables))
1306 {
1307 Db::bind("id", $id);
1308 $old = Db::query("SELECT * FROM ".$table." WHERE id = :id");
1309 $old = $old[0];
1310 if(!empty($old))
1311 {
1312 $ex = 0;
1313 if($table=="referrals")
1314 {
1315 if($old["confirmed"] == "0")
1316 {
1317 Db::bind("newstatus", "1");
1318 Db::bind("itemid", $old["id"]);
1319 $query = "UPDATE `referrals` SET `confirmed` = :newstatus WHERE id = :itemid";
1320 $ex = Db::query($query);
1321 if($ex)
1322 {
1323 $points = s("defaults/referrals_points");
1324 Wallet::move($points, "pending", "confirmed", $old["user_id"]);
1325 define("alert_success", "Confirmed");
1326 }
1327 else
1328 {
1329 define("alert_error", "Error - Update faild");
1330 }
1331 }
1332 else
1333 {
1334 define("alert_error", "Already confirmed");
1335 }
1336 }
1337 else if($table=="websites")
1338 {
1339 if($old["activated"] == "0")
1340 {
1341 Db::bind("newstatus", "1");
1342 $stat = "Disable Confirmation";
1343 }
1344 else
1345 {
1346 Db::bind("newstatus", "0");
1347 $stat = "Confirm";
1348 }
1349 Db::bind("itemid", $old["id"]);
1350 $query = "UPDATE `websites` SET `activated` = :newstatus WHERE id = :itemid";
1351 $ex = Db::query($query);
1352 if($ex)
1353 {
1354 define("alert_success", $stat);
1355 }
1356 else
1357 {
1358 define("alert_error", "Error - Update faild");
1359 }
1360 }
1361 else if($table=="payments" && $old["confirmed"] == "1")
1362 {
1363 Db::bind("id", $old["plan_id"]);
1364 $plan = Db::query("SELECT * FROM plans WHERE id = :id");
1365 $plan = $plan[0];
1366 if(!empty($plan))
1367 {
1368 Db::bind("newstatus", "2");
1369 Db::bind("itemid", $old["id"]);
1370 $query = "UPDATE `payments` SET `confirmed` = :newstatus WHERE id = :itemid";
1371 $ex = Db::query($query);
1372 if($plan["type"]=="upgrade")
1373 {
1374 if(Upgrade::up($old["user_id"], $plan["traffic_ratio"], $plan["website_slots"], $plan["session_slots"], $plan["duration"]) && $ex)
1375 {
1376 define("alert_success", "Confirmed");
1377 }
1378 else
1379 {
1380 Db::bind("newstatus", "1");
1381 Db::bind("itemid", $old["id"]);
1382 $query = "UPDATE `payments` SET `confirmed` = :newstatus WHERE id = :itemid";
1383 Db::query($query);
1384 define("alert_error", "Sorry something went wrong - please try again");
1385 }
1386 }
1387 else if($plan["type"]=="websites")
1388 {
1389 if(More::websites($old["user_id"], $plan["website_slots"]) && $ex)
1390 {
1391 define("alert_success", "Confirmed");
1392 }
1393 else
1394 {
1395 Db::bind("newstatus", "1");
1396 Db::bind("itemid", $old["id"]);
1397 $query = "UPDATE `payments` SET `confirmed` = :newstatus WHERE id = :itemid";
1398 Db::query($query);
1399 define("alert_error", "Sorry something went wrong - please try again");
1400 }
1401 }
1402 else if($plan["type"]=="sessions")
1403 {
1404 if(More::sessions($old["user_id"], $plan["session_slots"]) && $ex)
1405 {
1406 define("alert_success", "Confirmed");
1407 }
1408 else
1409 {
1410 Db::bind("newstatus", "1");
1411 Db::bind("itemid", $old["id"]);
1412 $query = "UPDATE `payments` SET `confirmed` = :newstatus WHERE id = :itemid";
1413 Db::query($query);
1414 define("alert_error", "Sorry something went wrong - please try again");
1415 }
1416 }
1417 else if($plan["type"]=="traffic")
1418 {
1419 if(More::traffic($old["user_id"], $plan["points"]) && $ex)
1420 {
1421 define("alert_success", "Confirmed");
1422 }
1423 else
1424 {
1425 Db::bind("newstatus", "1");
1426 Db::bind("itemid", $old["id"]);
1427 $query = "UPDATE `payments` SET `confirmed` = :newstatus WHERE id = :itemid";
1428 Db::query($query);
1429 define("alert_error", "Sorry something went wrong - please try again");
1430 }
1431 }
1432 else
1433 {
1434 define("alert_error", "wrong type");
1435 }
1436 }
1437 else
1438 {
1439 define("alert_error", "Sorry this plan it's no more exists");
1440 }
1441 }
1442 else
1443 {
1444 define("alert_error", "Already confirmed");
1445 }
1446 }
1447 else
1448 {
1449 define("alert_error", "wrong data");
1450 }
1451 }
1452 else
1453 {
1454 define("alert_error", "wrong table / status");
1455 }
1456 }
1457 else
1458 {
1459 define("alert_error", "empty data");
1460 }
1461 }
1462 $this->makejson();
1463 }
1464
1465 public function ajax_add($match="")
1466 {
1467 if(Auth::check("admins") && Check::this_referer())
1468 {
1469 $type = Request::post("kindofpost");
1470 if($type=="plan")
1471 {
1472 $plan_name = Request::post("plan_name");
1473 $plan_type = Request::post("plan_type");
1474 $plan_points = Request::post("plan_points");
1475 $plan_websites = Request::post("plan_websites");
1476 $plan_sessions = Request::post("plan_sessions");
1477 $plan_ratio = Request::post("plan_ratio");
1478 $plan_currency = Request::post("plan_currency");
1479 $plan_duration = Request::post("plan_duration")."-".Request::post("plan_duration_type");
1480 $plan_price = Request::post("plan_price");
1481 $plan_price = $this->double_number($plan_price);
1482 if(!empty($plan_name) && !empty($plan_type) && !empty($plan_currency))
1483 {
1484 $query = "INSERT INTO `plans` (`name`, `type`, `website_slots`, `session_slots`, `traffic_ratio`, `price`, `currency`, `duration`, `points`, `status`, `created_at`, `updated_at`) VALUES (:name, :type, :website_slots, :session_slots, :traffic_ratio, :price, :currency, :duration, :points, :status, :created_at, :updated_at)";
1485 if($plan_type == "upgrade")
1486 {
1487 Db::bind("name", $plan_name);
1488 Db::bind("type", "upgrade");
1489 Db::bind("website_slots", $plan_websites);
1490 Db::bind("session_slots", $plan_sessions);
1491 Db::bind("traffic_ratio", $plan_ratio);
1492 Db::bind("price", $plan_price);
1493 Db::bind("currency", $plan_currency);
1494 Db::bind("duration", $plan_duration);
1495 Db::bind("points", "");
1496 Db::bind("status", "1");
1497 Db::bind("created_at", time());
1498 Db::bind("updated_at", time());
1499 $ex = Db::query($query);
1500 }
1501 else if($plan_type == "traffic")
1502 {
1503 Db::bind("name", $plan_name);
1504 Db::bind("type", "traffic");
1505 Db::bind("website_slots", "");
1506 Db::bind("session_slots", "");
1507 Db::bind("traffic_ratio", "");
1508 Db::bind("price", $plan_price);
1509 Db::bind("currency", $plan_currency);
1510 Db::bind("points", $plan_points);
1511 Db::bind("status", "1");
1512 Db::bind("created_at", time());
1513 Db::bind("updated_at", time());
1514 $ex = Db::query($query);
1515 }
1516 else if($plan_type == "websites")
1517 {
1518 Db::bind("name", $plan_name);
1519 Db::bind("type", "websites");
1520 Db::bind("website_slots", $plan_websites);
1521 Db::bind("session_slots", "");
1522 Db::bind("traffic_ratio", "");
1523 Db::bind("price", $plan_price);
1524 Db::bind("currency", $plan_currency);
1525 Db::bind("points", "");
1526 Db::bind("status", "1");
1527 Db::bind("created_at", time());
1528 Db::bind("updated_at", time());
1529 $ex = Db::query($query);
1530 }
1531 else if($plan_type == "sessions")
1532 {
1533 Db::bind("name", $plan_name);
1534 Db::bind("type", "sessions");
1535 Db::bind("website_slots", "");
1536 Db::bind("session_slots", $plan_sessions);
1537 Db::bind("traffic_ratio", "");
1538 Db::bind("price", $plan_price);
1539 Db::bind("currency", $plan_currency);
1540 Db::bind("points", "");
1541 Db::bind("status", "1");
1542 Db::bind("created_at", time());
1543 Db::bind("updated_at", time());
1544 $ex = Db::query($query);
1545 }
1546 else
1547 {
1548 define("alert_error", "Sorry we cannot found this type");
1549 }
1550 if($ex)
1551 {
1552 define("alert_success", "Plan was added successfully");
1553 }
1554 else
1555 {
1556 define("alert_error", "Error - something went wrong, Please try again");
1557 }
1558 }
1559 else
1560 {
1561 define("alert_error", "Please complete the form");
1562 }
1563 }
1564 else if($type=="admin")
1565 {
1566 $username = strtolower(Request::post("admin_username"));
1567 $email = Request::post("admin_email");
1568 $password = Request::post("admin_password");
1569 $password2 = Request::post("admin_password2");
1570 if(!empty($username) && !empty($email) && !empty($password) && Check::is_safe($username, "iaA") && Check::is_email($email))
1571 {
1572 if(!Auth::check_username($username) && !Auth::check_email($email))
1573 {
1574 if($password==$password2)
1575 {
1576 $query = "INSERT INTO `admins` (`username`, `email`, `password`, `status`, `created_at`, `updated_at`) VALUES (:username, :email, :password, :status, :created_at, :updated_at)";
1577 Db::bind("username", $username);
1578 Db::bind("email", $email);
1579 Db::bind("password", Encryption::encode($password));
1580 Db::bind("status", "1");
1581 Db::bind("created_at", time());
1582 Db::bind("updated_at", time());
1583 $ex = Db::query($query);
1584 if($ex)
1585 {
1586 define("alert_success", "Done , a new admin was added.");
1587 }
1588 else
1589 {
1590 define("alert_error", "Error - something went wrong, Please try again");
1591 }
1592 }
1593 else
1594 {
1595 define("alert_error", "Passwords are incorrect please try again!");
1596 }
1597 }
1598 else
1599 {
1600 define("alert_error", "username or email is already exists please change it!");
1601 }
1602 }
1603 else
1604 {
1605 define("alert_error", "characters allowed on username/email is (a-z A-Z 0-9)");
1606 }
1607 }
1608 else if($type=="user")
1609 {
1610 $username = strtolower(Request::post("username"));
1611 $email = Request::post("email");
1612 $password = Request::post("password");
1613 $password2 = Request::post("password2");
1614 if(!empty($username) && !empty($email) && !empty($password) && Check::is_safe($username, "iaA") && Check::is_email($email))
1615 {
1616 Auth::table("users");
1617 if(!Auth::check_username($username) && !Auth::check_email($email))
1618 {
1619 Auth::table("admins");
1620 if($password==$password2)
1621 {
1622 $query = "INSERT INTO `users` (`username`, `email`, `password`, `status`, `created_at`, `updated_at`) VALUES (:username, :email, :password, :status, :created_at, :updated_at)";
1623 Db::bind("username", $username);
1624 Db::bind("email", $email);
1625 Db::bind("password", Encryption::encode($password));
1626 Db::bind("status", "1");
1627 Db::bind("created_at", time());
1628 Db::bind("updated_at", time());
1629 $ex = Db::query($query);
1630 if($ex)
1631 {
1632 define("alert_success", "Done , a new user was added.");
1633 }
1634 else
1635 {
1636 define("alert_error", "Error - something went wrong, Please try again");
1637 }
1638 }
1639 else
1640 {
1641 define("alert_error", "Passwords are incorrect please try again!");
1642 }
1643 }
1644 else
1645 {
1646 define("alert_error", "username or email is already exists please change it!");
1647 }
1648 }
1649 else
1650 {
1651 define("alert_error", "characters allowed on username/email is (a-z A-Z 0-9)");
1652 }
1653 }
1654 }
1655 $this->makejson();
1656 }
1657
1658 public function ajax_update($match="")
1659 {
1660 $id = $match["params"]["id"];
1661 if(Auth::check("admins") && Check::this_referer() && !empty($id))
1662 {
1663 $type = Request::post("kindofpost");
1664 if($type=="plan")
1665 {
1666 $plan_name = Request::post("plan_name");
1667 $plan_type = Request::post("plan_type");
1668 $plan_points = Request::post("plan_points");
1669 $plan_websites = Request::post("plan_websites");
1670 $plan_sessions = Request::post("plan_sessions");
1671 $plan_ratio = Request::post("plan_ratio");
1672 $plan_currency = Request::post("plan_currency");
1673 $plan_duration = Request::post("plan_duration")."-".Request::post("plan_duration_type");
1674 $plan_price = Request::post("plan_price");
1675 $plan_price = $this->double_number($plan_price);
1676 if(!empty($plan_name) && !empty($plan_type) && !empty($plan_currency))
1677 {
1678 $query = "UPDATE `plans` SET `name` = :name, `type` = :type, `website_slots` = :website_slots, `session_slots` = :session_slots, `traffic_ratio` = :traffic_ratio, `price` = :price, `currency` = :currency, `duration` = :duration, `points` = :points, `status` = :status, `created_at` = :created_at, `updated_at` = :updated_at WHERE id = :id";
1679 if($plan_type == "upgrade")
1680 {
1681 Db::bind("id", $id);
1682 Db::bind("name", $plan_name);
1683 Db::bind("type", "upgrade");
1684 Db::bind("website_slots", $plan_websites);
1685 Db::bind("session_slots", $plan_sessions);
1686 Db::bind("traffic_ratio", $plan_ratio);
1687 Db::bind("price", $plan_price);
1688 Db::bind("currency", $plan_currency);
1689 Db::bind("duration", $plan_duration);
1690 Db::bind("points", "");
1691 Db::bind("status", "1");
1692 Db::bind("created_at", time());
1693 Db::bind("updated_at", time());
1694 $ex = Db::query($query);
1695 }
1696 else if($plan_type == "traffic")
1697 {
1698 Db::bind("id", $id);
1699 Db::bind("name", $plan_name);
1700 Db::bind("type", "traffic");
1701 Db::bind("website_slots", "");
1702 Db::bind("session_slots", "");
1703 Db::bind("traffic_ratio", "");
1704 Db::bind("price", $plan_price);
1705 Db::bind("currency", $plan_currency);
1706 Db::bind("points", $plan_points);
1707 Db::bind("status", "1");
1708 Db::bind("created_at", time());
1709 Db::bind("updated_at", time());
1710 $ex = Db::query($query);
1711 }
1712 else if($plan_type == "websites")
1713 {
1714 Db::bind("id", $id);
1715 Db::bind("name", $plan_name);
1716 Db::bind("type", "websites");
1717 Db::bind("website_slots", $plan_websites);
1718 Db::bind("session_slots", "");
1719 Db::bind("traffic_ratio", "");
1720 Db::bind("price", $plan_price);
1721 Db::bind("currency", $plan_currency);
1722 Db::bind("points", "");
1723 Db::bind("status", "1");
1724 Db::bind("created_at", time());
1725 Db::bind("updated_at", time());
1726 $ex = Db::query($query);
1727 }
1728 else if($plan_type == "sessions")
1729 {
1730 Db::bind("id", $id);
1731 Db::bind("name", $plan_name);
1732 Db::bind("type", "sessions");
1733 Db::bind("website_slots", "");
1734 Db::bind("session_slots", $plan_sessions);
1735 Db::bind("traffic_ratio", "");
1736 Db::bind("price", $plan_price);
1737 Db::bind("currency", $plan_currency);
1738 Db::bind("points", "");
1739 Db::bind("status", "1");
1740 Db::bind("created_at", time());
1741 Db::bind("updated_at", time());
1742 $ex = Db::query($query);
1743 }
1744 else
1745 {
1746 define("alert_error", "Sorry we cannot found this type");
1747 }
1748 if($ex)
1749 {
1750 define("alert_success", "Plan was updated successfully");
1751 }
1752 else
1753 {
1754 define("alert_error", "Error - something went wrong, Please try again");
1755 }
1756 }
1757 else
1758 {
1759 define("alert_error", "Please complete the form");
1760 }
1761 }
1762 else if($type=="admin")
1763 {
1764 $username = strtolower(Request::post("edit_username"));
1765 $email = Request::post("edit_email");
1766 $password = Request::post("edit_password");
1767 $password2 = Request::post("edit_password2");
1768 $old = Getdata::one_admin($id);
1769 if(!empty($username) && !empty($email))
1770 {
1771 if(Check::is_safe($username, "iaA") && Check::is_email($email))
1772 {
1773 if(!Auth::check_username($username) or $old["username"]==$username)
1774 {
1775 if(!Auth::check_email($email) or $old["email"]==$email)
1776 {
1777 $query = "UPDATE `admins` SET `username` = :username, `email` = :email, `updated_at` = :updated_at WHERE id = :id";
1778 Db::bind("username", $username);
1779 Db::bind("email", $email);
1780 Db::bind("id", $id);
1781 Db::bind("updated_at", time());
1782 $ex = Db::query($query);
1783 if($ex)
1784 {
1785 define("alert_success", "Done , Updated.");
1786 }
1787 else
1788 {
1789 define("alert_error", "Error - something went wrong, Please try again");
1790 }
1791 }
1792 else
1793 {
1794 define("alert_error", "This email is already exists please change it!");
1795 }
1796 }
1797 else
1798 {
1799 define("alert_error", "This username is already exists please change it!");
1800 }
1801 }
1802 else
1803 {
1804 define("alert_error", "characters allowed on username/email is (a-z A-Z 0-9)");
1805 }
1806 }
1807 else if(!empty($password))
1808 {
1809 if($password==$password2)
1810 {
1811 $query = "UPDATE `admins` SET `password` = :password, `updated_at` = :updated_at WHERE id = :id";
1812 Db::bind("id", $id);
1813 Db::bind("password", Encryption::encode($password));
1814 Db::bind("updated_at", time());
1815 $ex = Db::query($query);
1816 if($ex)
1817 {
1818 define("alert_success", "Done , Updated.");
1819 }
1820 else
1821 {
1822 define("alert_error", "Error - something went wrong, Please try again");
1823 }
1824 }
1825 else
1826 {
1827 define("alert_error", "Passwords are incorrect please try again!");
1828 }
1829 }
1830 else
1831 {
1832 define("alert_error", "Please fill out all field !");
1833 }
1834 }
1835 else if($type=="user")
1836 {
1837 $username = strtolower(Request::post("edit_username"));
1838 $email = Request::post("edit_email");
1839 $websites = Request::post("edit_website_slots", "i");
1840 $sessions = Request::post("edit_session_slots", "i");
1841 $ratio = Request::post("edit_traffic_ratio", "i");
1842 $points = Request::post("edit_points");
1843 $password = Request::post("edit_password");
1844 $password2 = Request::post("edit_password2");
1845 $old = Getdata::one_user($id);
1846 if(empty($websites)){ $websites = 0; }
1847 if(empty($sessions)){ $sessions = 0; }
1848 if(empty($ratio)){ $ratio = 0; }
1849 if(empty($points)){ $points = 0; }
1850 if(!empty($username) && !empty($email))
1851 {
1852 if(Check::is_safe($username, "iaA") && Check::is_email($email))
1853 {
1854 Auth::table("users");
1855 if(!Auth::check_username($username) or $old["username"]==$username)
1856 {
1857 Auth::table("users");
1858 if(!Auth::check_email($email) or $old["email"]==$email)
1859 {
1860 Auth::table("admins");
1861 $query = "UPDATE `users` SET `username` = :username, `email` = :email, `website_slots` = :websites, `session_slots` = :sessions, `traffic_ratio` = :ratio, `points` = :points, `updated_at` = :updated_at WHERE id = :id";
1862 Db::bind("username", $username);
1863 Db::bind("email", $email);
1864 Db::bind("websites", $websites);
1865 Db::bind("sessions", $sessions);
1866 Db::bind("ratio", $ratio);
1867 Db::bind("points", $points);
1868 Db::bind("id", $id);
1869 Db::bind("updated_at", time());
1870 $ex = Db::query($query);
1871 if($ex)
1872 {
1873 define("alert_success", "Done , Updated.");
1874 }
1875 else
1876 {
1877 define("alert_error", "Error - something went wrong, Please try again");
1878 }
1879 }
1880 else
1881 {
1882 define("alert_error", "This email is already exists please change it!");
1883 }
1884 }
1885 else
1886 {
1887 define("alert_error", "This username is already exists please change it!");
1888 }
1889 }
1890 else
1891 {
1892 define("alert_error", "characters allowed on username/email is (a-z A-Z 0-9)");
1893 }
1894 }
1895 else if(!empty($password))
1896 {
1897 if($password==$password2)
1898 {
1899 $query = "UPDATE `users` SET `password` = :password, `updated_at` = :updated_at WHERE id = :id";
1900 Db::bind("id", $id);
1901 Db::bind("password", Encryption::encode($password));
1902 Db::bind("updated_at", time());
1903 $ex = Db::query($query);
1904 if($ex)
1905 {
1906 define("alert_success", "Done , Updated.");
1907 }
1908 else
1909 {
1910 define("alert_error", "Error - something went wrong, Please try again");
1911 }
1912 }
1913 else
1914 {
1915 define("alert_error", "Passwords are incorrect please try again!");
1916 }
1917 }
1918 else
1919 {
1920 define("alert_error", "Please fill out all field !");
1921 }
1922 }
1923 else if($type=="payment")
1924 {
1925 $user_id = Request::post("edit_payment_user_id");
1926 $plan_id = Request::post("edit_payment_plan_id");
1927 $payment_id = Request::post("edit_payment_id");
1928 $kind = Request::post("edit_payment_kind");
1929 $amount = Request::post("edit_payment_amount");
1930 $currency = Request::post("edit_payment_currency");
1931 $service = Request::post("edit_payment_service");
1932 $info = Request::post("edit_payment_info");
1933 $amount = $this->double_number($amount);
1934 $query = "UPDATE `payments` SET `user_id` = :user_id, `plan_id` = :plan_id, `payment_id` = :payment_id, `kind` = :kind, `amount` = :amount, `currency` = :currency, `payment_service` = :service, `payment_info` = :info WHERE id = :id";
1935 Db::bind("id", $id);
1936 Db::bind("user_id", $user_id);
1937 Db::bind("plan_id", $plan_id);
1938 Db::bind("payment_id", $payment_id);
1939 Db::bind("kind", $kind);
1940 Db::bind("amount", $amount);
1941 Db::bind("currency", $currency);
1942 Db::bind("service", $service);
1943 Db::bind("info", $info);
1944 $ex = Db::query($query);
1945 if($ex)
1946 {
1947 define("alert_success", "Done , Payment Updated.");
1948 }
1949 else
1950 {
1951 define("alert_error", "Error - something went wrong, Please try again");
1952 }
1953 }
1954 else if($type=="website")
1955 {
1956 $user_id = Request::post("edit_user_id");
1957 $website_url = Request::post("edit_website_url");
1958 $website_max_hits = Request::post("edit_website_max_hits");
1959 $website_max_hour_hits = Request::post("edit_website_max_hour_hits");
1960 $website_duration = Request::post("edit_website_duration");
1961 //$website_source = Request::post("edit_website_source");
1962 //$website_useragent = Request::post("edit_website_useragent");
1963 $get_target = Request::post("edit_website_geotarget");
1964 if(!empty($get_target) && is_array($get_target))
1965 {
1966 $geo_targeting = "";
1967 $list_of_countries = array_keys(s("geotarget/list"));
1968 foreach($get_target as $target)
1969 {
1970 if(in_array($target, $list_of_countries))
1971 {
1972 $geo_targeting .= "[".$target."]";
1973 }
1974 }
1975 }
1976 else
1977 {
1978 $geo_targeting = "[ALL]";
1979 }
1980 $query = "UPDATE `websites` SET `user_id` = :user_id, `url` = :url, `max_hits` = :max_hits, `max_hour_hits` = :max_hour_hits, `duration` = :duration, `source` = :source, `useragent` = :useragent, `geolocation` = :geolocation, `updated_at` = :uat WHERE id = :id";
1981 Db::bind("id", $id);
1982 Db::bind("user_id", $user_id);
1983 Db::bind("url", $website_url);
1984 Db::bind("max_hits", $website_max_hits);
1985 Db::bind("max_hour_hits", $website_max_hour_hits);
1986 Db::bind("duration", $website_duration);
1987 Db::bind("source", "");
1988 Db::bind("useragent", "");
1989 Db::bind("geolocation", $geo_targeting);
1990 Db::bind("uat", time());
1991 $ex = Db::query($query);
1992 if($ex)
1993 {
1994 define("alert_success", "Done , Website Updated.");
1995 }
1996 else
1997 {
1998 define("alert_error", "Error - something went wrong, Please try again");
1999 }
2000 }
2001 }
2002 $this->makejson();
2003 }
2004}
2005?>