Advertisement
ThisIsMac

Untitled

Jan 11th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 32.56 KB | None | 0 0
  1. <?php
  2. class VoterController extends VoteAppController {
  3.  
  4. public $components = array('Configuration', 'Configuration');
  5.  
  6. public function index() {
  7. $this->loadModel('VoteConfiguration');
  8. $search = $this->VoteConfiguration->find('all');
  9. if(!empty($search)) {
  10.  
  11. $this->set('websites', unserialize($search[0]['VoteConfiguration']['websites']));
  12.  
  13. $rewards = $search[0]['VoteConfiguration']['rewards'];
  14. $rewards = unserialize($rewards);
  15. $this->set(compact('rewards'));
  16.  
  17. $this->loadModel('User');
  18. $ranking = $this->User->find('all', array('limit' => '10', 'order' => 'vote desc'));
  19. $this->set(compact('ranking'));
  20. } else {
  21. throw new NotFoundException();
  22. }
  23. }
  24.  
  25. public function setWebsite() {
  26. $this->autoRender = false;
  27. if($this->request->is('ajax')) {
  28. if(!empty($this->request->data['website']) OR $this->request->data['website'] == 0) {
  29. $this->Session->write('vote.website', $this->request->data['website']);
  30.  
  31. $this->loadModel('VoteConfiguration');
  32. $config = $this->VoteConfiguration->find('first');
  33. $websites = unserialize($config['VoteConfiguration']['websites']);
  34.  
  35. if($websites[$this->request->data['website']]['website_type'] == 'rpg') {
  36. echo json_encode(array('page' => 'http://rpg-paradize.com/?page=vote&vote='.@$websites[$this->request->data['website']]['rpg_id'], 'website_type' => @$websites[$this->request->data['website']]['website_type']));
  37. } else {
  38. echo json_encode(array('page' => @$websites[$this->request->data['website']]['page_vote'], 'website_type' => @$websites[$this->request->data['website']]['website_type']));
  39. }
  40. }
  41. }
  42. }
  43.  
  44. public function setPseudo() {
  45. $this->autoRender = false;
  46. if($this->request->is('ajax')) {
  47. $this->loadModel('User');
  48. $user_rank = $this->User->find('first', array('conditions' => array('pseudo' => $this->request->data['pseudo'])));
  49. if(!empty($user_rank) && $this->Permissions->have($user_rank['User']['rank'], 'VOTE') == "true") {
  50. if(!empty($this->request->data['pseudo'])) {
  51. if($this->Connect->user_exist($this->request->data['pseudo'])) {
  52. $this->loadModel('Vote');
  53. $get_last_vote = $this->Vote->find('first', array('conditions' => array('OR' => array('username' => $this->request->data['pseudo'], 'ip' => $_SERVER['REMOTE_ADDR']), 'website' => $this->Session->read('vote.website'))));
  54.  
  55. if(!empty($get_last_vote['Vote']['created'])) {
  56. $now = time();
  57. $last_vote = ($now - strtotime($get_last_vote['Vote']['created']))/60;
  58. } else {
  59. $last_vote = null;
  60. }
  61.  
  62. $this->loadModel('VoteConfiguration');
  63. $config = $this->VoteConfiguration->find('first');
  64.  
  65.  
  66. $websites = unserialize($config['VoteConfiguration']['websites']);
  67. if(isset($websites[$this->Session->read('vote.website')])) {
  68. $time_vote = $websites[$this->Session->read('vote.website')]['time_vote'];
  69.  
  70. if(empty($last_vote) OR $last_vote > $time_vote) {
  71.  
  72. $this->Session->write('vote.pseudo', $this->request->data['pseudo']);
  73. echo $this->Lang->get('VOTE_LOGIN_SUCCESS').'|true';
  74.  
  75. } else {
  76. echo $this->Lang->get('ALREADY_VOTED').'|false';
  77. }
  78. } else {
  79. echo $this->Lang->get('ALREADY_VOTED').'|false';
  80. }
  81. } else {
  82. echo $this->Lang->get('UNKNOWN_USERNAME').'|false';
  83. }
  84. }
  85. } else {
  86. echo $this->Lang->get('UNKNOWN_USERNAME').'|false';
  87. }
  88. } else {
  89. throw new InternalErrorException();
  90. }
  91. }
  92.  
  93. public function checkOut() {
  94. $this->autoRender = false;
  95. if($this->request->is('ajax')) {
  96. if(!empty($this->request->data['out']) && $this->Session->check('vote.website') && $this->Session->check('vote.pseudo')) {
  97.  
  98. $this->loadModel('VoteConfiguration');
  99. $config = $this->VoteConfiguration->find('first');
  100. $websites = unserialize($config['VoteConfiguration']['websites']);
  101. $url = $websites[$this->Session->read('vote.website')]['page_vote'];
  102. // exemple : http://rpg-paradize.com/site-+FR+++RESET++ObsiFight+Serveur+PvP+Faction+2424+1.8-44835
  103.  
  104. $user_agent = 'Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1'; // simule Firefox 4.
  105. $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
  106. $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
  107. $header[] = "Cache-Control: max-age=0";
  108. $header[] = "Connection: keep-alive";
  109. $header[] = "Keep-Alive: 300";
  110. $header[] = "Accept-Charset: utf-8";
  111. $header[] = "Accept-Language: fr"; // langue fr.
  112. $header[] = "Pragma: "; // Simule un navigateur
  113.  
  114. $ch = curl_init();
  115. curl_setopt($ch, CURLOPT_URL, $url); // l'url visité
  116. curl_setopt($ch, CURLOPT_FAILONERROR, 1);// Gestion d'erreur
  117. //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // autorise la redirection
  118. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // stock la response dans une variable
  119. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  120. curl_setopt($ch, CURLOPT_PORT, 80); // set port 80
  121. curl_setopt($ch, CURLOPT_TIMEOUT, 15); // timeout curl à 15 secondes.
  122.  
  123. curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
  124. $result=curl_exec($ch);
  125.  
  126. $str = substr($result, strpos($result, 'Clic Sortant'), 20);
  127. $out = filter_var($str, FILTER_SANITIZE_NUMBER_INT);
  128. $array = array($out, $out-1, $out-2, $out-3, $out+1, $out+2, $out+3);
  129.  
  130. if(in_array($this->request->data['out'], $array)) {
  131.  
  132. $this->Session->write('vote.out', true);
  133. echo $this->Lang->get('OUT_SUCCESS').'|true';
  134.  
  135. } else {
  136. echo $this->Lang->get('OUT_INVALID').'|false';
  137. }
  138.  
  139. }
  140. } else {
  141. throw new InternalErrorException();
  142. }
  143. }
  144.  
  145. public function getRewards() {
  146. $when = (isset($this->request->data['when'])) ? $this->request->data['when'] : 'now';
  147. $this->autoRender = false;
  148. if($this->request->is('ajax')) {
  149. if($this->Session->check('vote.website') && $this->Session->check('vote.pseudo')) {
  150. $this->loadModel('VoteConfiguration');
  151. $config = $this->VoteConfiguration->find('first');
  152. $websites = unserialize($config['VoteConfiguration']['websites']);
  153. $website = $websites[$this->Session->read('vote.website')];
  154. if($this->Session->check('vote.out') || $website['website_type'] == "other") {
  155.  
  156. // check si il a pas déjà voté sur ce site
  157. $this->loadModel('Vote');
  158. $get_last_vote = $this->Vote->find('first', array('conditions' => array('OR' => array('username' => $this->Session->read('vote.pseudo'), 'ip' => $_SERVER['REMOTE_ADDR']), 'website' => $this->Session->read('vote.website'))));
  159.  
  160. if(!empty($get_last_vote['Vote']['created'])) {
  161. $now = time();
  162. $last_vote = ($now - strtotime($get_last_vote['Vote']['created']))/60;
  163. } else {
  164. $last_vote = null;
  165. }
  166.  
  167. $this->loadModel('VoteConfiguration');
  168. $config = $this->VoteConfiguration->find('first');
  169. $websites = unserialize($config['VoteConfiguration']['websites']);
  170. if(isset($websites[$this->Session->read('vote.website')])) {
  171. $time_vote = $websites[$this->Session->read('vote.website')]['time_vote'];
  172.  
  173. if(empty($last_vote) OR $last_vote > $time_vote) {
  174.  
  175. // on incrémente le vote
  176. if(empty($get_last_vote)) {
  177. $this->Vote->read(null, null);
  178. $this->Vote->set(array(
  179. 'username' => $this->Session->read('vote.pseudo'),
  180. 'ip' => $_SERVER['REMOTE_ADDR'],
  181. 'website' => $this->Session->read('vote.website')
  182. ));
  183. $this->Vote->save();
  184. } else {
  185. $this->Vote->read(null, $get_last_vote['Vote']['id']);
  186. $this->Vote->set(array(
  187. 'username' => $this->Session->read('vote.pseudo'),
  188. 'ip' => $_SERVER['REMOTE_ADDR'],
  189. 'website' => $this->Session->read('vote.website'),
  190. 'created' => date('Y-m-d H:i:s')
  191. ));
  192. $this->Vote->save();
  193. }
  194. $this->loadModel('User');
  195. $user_id = $this->User->find('all', array('conditions' => array('pseudo' => $this->Session->read('vote.pseudo'))));
  196. $vote_nbr = $user_id[0]['User']['vote'] + 1;
  197. $this->User->read(null, $user_id['0']['User']['id']);
  198. $this->User->set(array(
  199. 'vote' => $vote_nbr
  200. ));
  201. $this->User->save();
  202.  
  203. // on cast l'event
  204. $this->getEventManager()->dispatch(new CakeEvent('onVote', $this));
  205.  
  206.  
  207. if($when == 'now') { // si c'est maintenant
  208. $rewards = unserialize($config['VoteConfiguration']['rewards']);
  209. $probability_all = 0;
  210. foreach ($rewards as $key => $value) {
  211. $probability_all = $probability_all + $value['proba'];
  212. $rewards_rand[$key] = $value['proba'];
  213. }
  214.  
  215. $reward = $this->random($rewards_rand, $probability_all);
  216.  
  217. $this->getEventManager()->dispatch(new CakeEvent('beforeRecieveRewards', $this, $reward));
  218.  
  219. if($rewards[$reward]['type'] == 'server') { // si c'est une commande serveur
  220. $config['0']['VoteConfiguration']['servers'] = unserialize($config['VoteConfiguration']['servers']);
  221. if(!empty($config['0']['VoteConfiguration']['servers'])) {
  222. foreach ($config['0']['VoteConfiguration']['servers'] as $key => $value) {
  223. $servers_online[] = $this->Server->online($value);
  224. }
  225. } else {
  226. $servers_online = array($this->Server->online());
  227. }
  228. if(!in_array(false, $servers_online)) {
  229.  
  230. if(empty($config['0']['VoteConfiguration']['servers'])) {
  231. $cmd = str_replace('{PLAYER}', $this->Session->read('vote.pseudo'), $rewards[$reward]['command']);
  232. $this->Server->send_command($cmd); // on envoie la commande puis enregistre le vote
  233. $msg = $this->Lang->get('VOTE_SUCCESS_SERVER');
  234. $msg = str_replace('{PLAYER}', $this->Session->read('vote.pseudo'), $msg);
  235. $msg = str_replace('{REWARD}', $rewards[$reward]['name'], $msg);
  236. $this->Server->send_command('bc '.$msg);
  237.  
  238. } else {
  239. foreach ($config['0']['VoteConfiguration']['servers'] as $key => $value) {
  240. $pseudo = $this->Session->read('vote.pseudo');
  241. $cmd = str_replace('{PLAYER}', $pseudo, $rewards[$reward]['command']);
  242. $this->Server->send_command($cmd); // on envoie la commande puis enregistre le vote
  243. $msg = $this->Lang->get('VOTE_SUCCESS_SERVER');
  244. $msg = str_replace('{PLAYER}', $pseudo, $msg);
  245. $msg = str_replace('{REWARD}', $rewards[$reward]['name'], $msg);
  246. $this->Server->send_command('bc '.$msg);
  247. }
  248. }
  249.  
  250. echo $this->Lang->get('VOTE_SUCCESS').' '.$this->Lang->get('REWARD').' : <b>'.$rewards[$reward]['name'].'</b>.|true';
  251.  
  252. } else {
  253. echo $this->Lang->get('NEED_SERVER_ON').'|false';
  254. }
  255.  
  256. } elseif($rewards[$reward]['type'] == 'money') { // si c'est des points boutique
  257.  
  258. $money = $this->Connect->get_to_user('money', $this->Session->read('vote.pseudo'));
  259. $money = $money + intval($rewards[$reward]['how']);
  260. $this->Connect->set_to_user('money', $money, $this->Session->read('vote.pseudo'));
  261.  
  262. $msg = $this->Lang->get('VOTE_SUCCESS_SERVER');
  263. $msg = str_replace('{PLAYER}', $this->Session->read('vote.pseudo'), $msg);
  264. $msg = str_replace('{REWARD}', $rewards[$reward]['how'].' golds', $msg);
  265. $this->Server->send_command('bc '.$msg);
  266.  
  267. echo $this->Lang->get('VOTE_SUCCESS').' '.$this->Lang->get('REWARDS').' : <b>'.$rewards[$reward]['how'].' '.$this->Configuration->get_money_name().'</b>.|true';
  268.  
  269. } else {
  270. echo $this->Lang->get('INTERNAL_ERROR').'|false';
  271. }
  272. } else { // si c'est plus tard
  273. $this->Connect->set('rewards_waited', ($this->Session->read('vote.pseudo') + 1));
  274. echo $this->Lang->get('REWARDS_SUCCESS_SET_WAITED').'|true';
  275. }
  276.  
  277. $this->Session->delete('vote');
  278.  
  279. } else {
  280. echo $this->Lang->get('ALREADY_VOTED').'|false';
  281.  
  282. $this->Session->delete('vote');
  283. }
  284. } else {
  285. echo $this->Lang->get('ALREADY_VOTED').'|false';
  286. }
  287.  
  288. } else {
  289. echo $this->Lang->get('OUT_INVALID').'|false';
  290. }
  291. } else {
  292. echo $this->Lang->get('UNKNOWN_USERNAME').'|false';
  293. }
  294. } else {
  295. throw new InternalErrorException();
  296. }
  297. }
  298.  
  299. private function random($rewards, $probability_all) {
  300. $pct = 1000;
  301. $rand = mt_rand(0, $pct);
  302. $items = array();
  303.  
  304. foreach ($rewards as $key => $value) {
  305. $items[$key] = $value / $probability_all;
  306. }
  307.  
  308. $i = 0;
  309. asort($items);
  310.  
  311. foreach ($items as $name => $value) {
  312. if ($rand <= $i+=($value * $pct)) {
  313. $reward = $name;
  314. break;
  315. }
  316. }
  317. return $reward;
  318. }
  319.  
  320. public function get_reward() {
  321. $this->autoRender = false;
  322. if($this->Connect->connect() && $this->Connect->get('rewards_waited') > 0) {
  323. $this->loadModel('VoteConfiguration');
  324. $config = $this->VoteConfiguration->find('first');
  325.  
  326. // on lui donne ses récompenses
  327. if($config['VoteConfiguration']['rewards_type'] == 1) { // toutes les récompenses
  328.  
  329. $rewards = unserialize($config['VoteConfiguration']['rewards']);
  330.  
  331. $this->getEventManager()->dispatch(new CakeEvent('beforeRecieveRewards', $this, $rewards));
  332.  
  333. foreach ($rewards as $key => $value) { // on le fais pour toute les commandes
  334.  
  335. if($value['type'] == 'server') { // si c'est une commande serveur
  336.  
  337. $config['0']['VoteConfiguration']['servers'] = unserialize($config['VoteConfiguration']['servers']);
  338. if(!empty($config['0']['VoteConfiguration']['servers'])) {
  339. foreach ($config['0']['VoteConfiguration']['servers'] as $k => $v) {
  340. $servers_online[] = $this->Server->online($v);
  341. }
  342. } else {
  343. $servers_online = array($this->Server->online());
  344. }
  345. if(!in_array(false, $servers_online)) {
  346. if(empty($config['0']['VoteConfiguration']['servers'])) {
  347. $cmd = str_replace('{PLAYER}', $this->Session->read('vote.pseudo'), $rewards[$reward]['command']);
  348. $this->Server->send_command($cmd); // on envoie la commande puis enregistre le vote
  349. $msg = $this->Lang->get('VOTE_SUCCESS_SERVER');
  350. $msg = str_replace('{PLAYER}', $this->Session->read('vote.pseudo'), $msg);
  351. $msg = str_replace('{REWARD}', $rewards[$reward]['name'], $msg);
  352. $this->Server->send_command('bc '.$msg);
  353.  
  354. } else {
  355. foreach ($config['0']['VoteConfiguration']['servers'] as $key => $value) {
  356. $pseudo = $this->Session->read('vote.pseudo');
  357. $cmd = str_replace('{PLAYER}', $pseudo, $rewards[$reward]['command']);
  358. $this->Server->send_command($cmd); // on envoie la commande puis enregistre le vote
  359. $msg = $this->Lang->get('VOTE_SUCCESS_SERVER');
  360. $msg = str_replace('{PLAYER}', $pseudo, $msg);
  361. $msg = str_replace('{REWARD}', $rewards[$reward]['name'], $msg);
  362. $this->Server->send_command('bc '.$msg);
  363. }
  364. }
  365.  
  366. $success_msg[] = $value['name'];
  367.  
  368. } else {
  369.  
  370. $success_msg[] = 'server_error';
  371. }
  372.  
  373. } elseif($value['type'] == 'money') { // si c'est des points boutique
  374.  
  375. $money = $this->Connect->get_to_user('money', $this->Connect->get_pseudo());
  376. $money = $money + intval($value['how']);
  377. $this->Connect->set_to_user('money', $money, $this->Connect->get_pseudo());
  378. $msg = $this->Lang->get('VOTE_SUCCESS_SERVER');
  379. $msg = str_replace('{PLAYER}', $this->Session->read('vote.pseudo'), $msg);
  380. $msg = str_replace('{REWARD}', $rewards[$reward]['how'].' golds', $msg);
  381. $this->Server->send_command('bc '.$msg);
  382.  
  383. $success_msg[] = $value['how'].' '.$this->Configuration->get_money_name();
  384.  
  385. } else {
  386. $success_msg[] = 'internal_error';
  387. }
  388.  
  389. }
  390.  
  391. if(in_array('server_error', $success_msg)) {
  392. $this->Session->setFlash($this->Lang->get('NEED_SERVER_ON'), 'default.error');
  393. $this->redirect(array('controller' => 'user', 'action' => 'profile', 'plugin' => false));
  394. } elseif (in_array('internal_error', $success_msg)) {
  395. $this->Session->setFlash($this->Lang->get('INTERNAL_ERROR'), 'default.error');
  396. $this->redirect(array('controller' => 'user', 'action' => 'profile', 'plugin' => false));
  397. } else {
  398. $flash = $this->Lang->get('VOTE_SUCCESS').' ! ';
  399. if(!empty($success_msg)) {
  400. $flash = $this->Lang->get('REWARDS').' : ';
  401.  
  402. $i = 0;
  403. $count = count($success_msg);
  404. foreach ($success_msg as $k => $v) {
  405. $i++;
  406. $flash = '<b>'.$v.'</b>';
  407. if($i < $count) {
  408. $flash = ', ';
  409. } else {
  410. $flash = '.|true';
  411. }
  412. }
  413. }
  414.  
  415. // on lui enlève la récompense en attente
  416. $this->Connect->set('rewards_waited', ($this->Connect->get('rewards_waited') - 1));
  417. // puis on redirige
  418. $this->Session->setFlash($flash, 'default.success');
  419. $this->redirect(array('controller' => 'user', 'action' => 'profile', 'plugin' => false));
  420. }
  421.  
  422. } else { // récompenses aléatoire selon probabilité
  423. $rewards = unserialize($config['VoteConfiguration']['rewards']);
  424. $probability_all = 0;
  425. foreach ($rewards as $key => $value) {
  426. $probability_all = $probability_all + $value['proba'];
  427. $rewards_rand[$key] = $value['proba'];
  428. }
  429.  
  430. $reward = $this->random($rewards_rand, $probability_all);
  431.  
  432. $this->getEventManager()->dispatch(new CakeEvent('beforeRecieveRewards', $this, $reward));
  433.  
  434. if($rewards[$reward]['type'] == 'server') { // si c'est une commande serveur
  435. $config['0']['VoteConfiguration']['servers'] = unserialize($config['VoteConfiguration']['servers']);
  436. if(!empty($config['0']['VoteConfiguration']['servers'])) {
  437. foreach ($config['0']['VoteConfiguration']['servers'] as $key => $value) {
  438. $servers_online[] = $this->Server->online($value);
  439. }
  440. } else {
  441. $servers_online = array($this->Server->online());
  442. }
  443. if(!in_array(false, $servers_online)) {
  444.  
  445. if(empty($config['0']['VoteConfiguration']['servers'])) {
  446. $cmd = str_replace('{PLAYER}', $this->Connect->get_pseudo(), $rewards[$reward]['command']);
  447. $this->Server->send_command($cmd); // on envoie la commande puis enregistre le vote
  448. $msg = $this->Lang->get('VOTE_SUCCESS_SERVER');
  449. $msg = str_replace('{PLAYER}', $this->Connect->get_pseudo(), $msg);
  450. $msg = str_replace('{REWARD}', $rewards[$reward]['name'], $msg);
  451. $this->Server->send_command('bc '.$msg);
  452.  
  453. } else {
  454. foreach ($config['0']['VoteConfiguration']['servers'] as $key => $value) {
  455. $pseudo = $this->Connect->get_pseudo();
  456. $cmd = str_replace('{PLAYER}', $pseudo, $rewards[$reward]['command']);
  457. $this->Server->send_command($cmd); // on envoie la commande puis enregistre le vote
  458. $msg = $this->Lang->get('VOTE_SUCCESS_SERVER');
  459. $msg = str_replace('{PLAYER}', $pseudo, $msg);
  460. $msg = str_replace('{REWARD}', $rewards[$reward]['name'], $msg);
  461. $this->Server->send_command('bc '.$msg);
  462. }
  463. }
  464.  
  465. $this->Connect->set('rewards_waited', ($this->Connect->get('rewards_waited') - 1));
  466.  
  467. $this->Session->setFlash($this->Lang->get('VOTE_SUCCESS').' '.$this->Lang->get('REWARD').' : <b>'.$rewards[$reward]['name'].'</b>.', 'default.success');
  468. $this->redirect(array('controller' => 'user', 'action' => 'profile', 'plugin' => false));
  469.  
  470. } else {
  471. $this->Session->setFlash($this->Lang->get('NEED_SERVER_ON'), 'default.error');
  472. $this->redirect(array('controller' => 'user', 'action' => 'profile', 'plugin' => false));
  473. }
  474.  
  475. } elseif($rewards[$reward]['type'] == 'money') { // si c'est des points boutique
  476.  
  477. $money = $this->Connect->get_to_user('money', $this->Connect->get_pseudo());
  478. $money = $money + intval($rewards[$reward]['how']);
  479. $this->Connect->set_to_user('money', $money, $this->Connect->get_pseudo());
  480.  
  481. $this->Connect->set('rewards_waited', ($this->Connect->get('rewards_waited') - 1));
  482. $msg = $this->Lang->get('VOTE_SUCCESS_SERVER');
  483. $msg = str_replace('{PLAYER}', $this->Connect->get_pseudo(), $msg);
  484. $msg = str_replace('{REWARD}', $rewards[$reward]['how'].' golds', $msg);
  485. $this->Server->send_command('bc '.$msg);
  486.  
  487. $this->Session->setFlash($this->Lang->get('VOTE_SUCCESS').' '.$this->Lang->get('REWARDS').' : <b>'.$rewards[$reward]['how'].' '.$this->Configuration->get_money_name().'</b>.', 'default.success');
  488. $this->redirect(array('controller' => 'user', 'action' => 'profile'));
  489.  
  490. } else {
  491. $this->Session->setFlash($this->Lang->get('INTERNAL_ERROR'), 'default.error');
  492. $this->redirect(array('controller' => 'user', 'action' => 'profile', 'plugin' => false));
  493. }
  494.  
  495. }
  496. } else {
  497. $this->redirect('/');
  498. }
  499. }
  500.  
  501. public function admin_index() {
  502. if($this->Connect->connect() AND $this->Connect->if_admin()) {
  503. $this->layout = "admin";
  504.  
  505. $this->loadModel('VoteConfiguration');
  506. $vote = $this->VoteConfiguration->find('first');
  507. if(!empty($vote)) {
  508. $vote = $vote['VoteConfiguration'];
  509. $vote['rewards'] = unserialize($vote['rewards']);
  510. $vote['websites'] = unserialize($vote['websites']);
  511. } else {
  512. $vote = array();
  513. }
  514. //debug($vote['rewards']);
  515. $this->set(compact('vote'));
  516.  
  517. $this->loadModel('Server');
  518. $vote['servers'] = unserialize($vote['servers']);
  519. if(!empty($vote['servers'])) {
  520. $selected_server = array();
  521. foreach ($vote['servers'] as $key => $value) {
  522. $d = $this->Server->find('first', array('conditions' => array('id' => $value)));
  523. if(!empty($d)) {
  524. $selected_server[] = $d['Server']['id'];
  525. }
  526. }
  527. } else {
  528. $selected_server = array();
  529. }
  530. $this->set(compact('selected_server'));
  531.  
  532. $search_servers = $this->Server->find('all');
  533. if(!empty($search_servers)) {
  534. foreach ($search_servers as $v) {
  535. $servers[$v['Server']['id']] = $v['Server']['name'];
  536. }
  537. } else {
  538. $servers = array();
  539. }
  540. $this->set(compact('servers'));
  541.  
  542. $this->set('title_for_layout',$this->Lang->get('VOTE_TITLE'));
  543. } else {
  544. $this->redirect('/');
  545. }
  546. }
  547.  
  548. public function admin_reset() {
  549. if($this->Connect->connect() AND $this->Connect->if_admin()) {
  550. $this->layout = null;
  551.  
  552. $this->loadModel('Vote');
  553. $this->Vote->deleteAll(array('1' => '1'));
  554. $this->loadModel('User');
  555. $this->User->updateAll(array('vote' => 0));
  556. $this->History->set('RESET', 'vote');
  557. $this->Session->setFlash($this->Lang->get('RESET_VOTE_SUCCESS'), 'default.success');
  558. $this->redirect(array('controller' => 'voter', 'action' => 'index', 'admin' => true));
  559. }
  560. }
  561.  
  562. public function admin_add_ajax() {
  563. if($this->Connect->connect() AND $this->Connect->if_admin()) {
  564. $this->layout = null;
  565.  
  566. if($this->request->is('post')) {
  567. if(!empty($this->request->data['servers']) AND !empty($this->request->data['website'][0]['page_vote']) AND !empty($this->request->data['website'][0]['time_vote']) AND !empty($this->request->data['website'][0]['website_type']) AND $this->request->data['rewards_type'] == '0' OR $this->request->data['rewards_type'] == '1') {
  568. if(!empty($this->request->data['rewards'][0]['name']) && $this->request->data['rewards'][0]['name'] != "undefined" && !empty($this->request->data['rewards'][0]['type']) && $this->request->data['rewards'][0]['type'] != "undefined") {
  569. $this->loadModel('VoteConfiguration');
  570. /*
  571. REWARDS -> serialize();
  572.  
  573. Structure = array(
  574. array(
  575. 'type' => money/server
  576. - 'how' => 10 - pour la money
  577. - 'command' => say e - pour le server
  578. )
  579.  
  580. )
  581.  
  582. */
  583.  
  584. if($this->request->data['rewards_type'] == 0) {
  585. foreach ($this->request->data['rewards'] as $key => $value) {
  586. if(!isset($value['proba']) || empty($value['proba'])) {
  587. echo $this->Lang->get('COMPLETE_ALL_FIELDS').'|false';
  588. die();
  589. }
  590. }
  591. }
  592.  
  593. $rewards = serialize($this->request->data['rewards']);
  594.  
  595. $vote = $this->VoteConfiguration->find('first');
  596. if(!empty($vote)) {
  597. $this->VoteConfiguration->read(null, 1);
  598. } else {
  599. $this->VoteConfiguration->create();
  600. }
  601. $this->VoteConfiguration->set(array(
  602. 'rewards_type' => $this->request->data['rewards_type'],
  603. 'rewards' => $rewards,
  604. 'websites' => serialize($this->request->data['website']),
  605. 'servers' => serialize($this->request->data['servers'])
  606. ));
  607. $this->VoteConfiguration->save();
  608. $this->History->set('EDIT_CONFIG', 'vote');
  609. $this->Session->setFlash($this->Lang->get('CONFIGURATION_SAVE'), 'default.success');
  610. echo $this->Lang->get('CONFIGURATION_SAVE').'|true';
  611. } else {
  612. echo $this->Lang->get('COMPLETE_ALL_FIELDS').'|false';
  613. }
  614. } else {
  615. echo $this->Lang->get('COMPLETE_ALL_FIELDS').'|false';
  616. }
  617. } else {
  618. echo $this->Lang->get('NOT_POST').'|false';
  619. }
  620. } else {
  621. $this->redirect('/');
  622. }
  623. }
  624. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement