/mods/squads/new.php

https://github.com/ichraffsnicht/ClanSphere-Enhanced · PHP · 168 lines · 134 code · 32 blank · 2 comment · 23 complexity · dcf042b658f6cf1ece1387fd65aa180c MD5 · raw file

  1. <?php
  2. // ClanSphere 2010 - www.clansphere.net
  3. // $Id$
  4. $cs_lang = cs_translate('squads');
  5. $files = cs_files();
  6. $op_squads = cs_sql_option(__FILE__,'squads');
  7. $op_clans = cs_sql_option(__FILE__,'clans');
  8. $clans_pwd = isset($_POST['clans_pwd']) ? $_POST['clans_pwd'] : '';
  9. $data = array();
  10. $data['if']['gamesmod'] = empty($account['access_games']) ? FALSE : TRUE;
  11. $img_filetypes = array('gif','jpg','png');
  12. if(isset($_POST['submit'])) {
  13. $cs_squads['clans_id'] = $_POST['clans_id'];
  14. $cs_squads['games_id'] = empty($_POST['games_id']) ? 0 : $_POST['games_id'];
  15. $cs_squads['squads_name'] = $_POST['squads_name'];
  16. $cs_squads['squads_order'] = empty($_POST['squads_order']) ? $op_squads['def_order'] : $_POST['squads_order'];
  17. $cs_squads['squads_pwd'] = $_POST['squads_pwd'];
  18. $error = '';
  19. if (!empty($_POST['new_clan']) && !empty($clans_pwd)) {
  20. $cells = array('clans_name', 'clans_short','clans_pwd', 'users_id');
  21. $values = array($_POST['new_clan'], $_POST['new_clan'], $clans_pwd, $account['users_id']);
  22. cs_sql_insert(__FILE__,'clans',$cells,$values);
  23. $cs_squads['clans_id'] = cs_sql_insertid(__FILE__);
  24. }
  25. $img_size = false;
  26. if(!empty($files['picture']['tmp_name']))
  27. $img_size = getimagesize($files['picture']['tmp_name']);
  28. if(!empty($files['picture']['tmp_name']) AND empty($img_size) OR $img_size[2] > 3) {
  29. $error .= $cs_lang['ext_error'] . cs_html_br(1);
  30. }
  31. elseif(!empty($files['picture']['tmp_name'])) {
  32. switch($img_size[2]) {
  33. case 1:
  34. $extension = 'gif'; break;
  35. case 2:
  36. $extension = 'jpg'; break;
  37. case 3:
  38. $extension = 'png'; break;
  39. }
  40. if($img_size[0]>$op_squads['max_width']) {
  41. $error .= $cs_lang['too_wide'] . cs_html_br(1);
  42. }
  43. if($img_size[1]>$op_squads['max_height']) {
  44. $error .= $cs_lang['too_high'] . cs_html_br(1);
  45. }
  46. if($files['picture']['size']>$op_squads['max_size']) {
  47. $error .= $cs_lang['too_big'] . cs_html_br(1);
  48. }
  49. }
  50. if(empty($cs_squads['clans_id'])) {
  51. $error .= $cs_lang['no_'.$op_clans['label']] . cs_html_br(1);
  52. }
  53. if(empty($cs_squads['squads_name'])) {
  54. $error .= $cs_lang['no_name'] . cs_html_br(1);
  55. }
  56. $where = "squads_name = '" . cs_sql_escape($cs_squads['squads_name']) . "'";
  57. $search = cs_sql_count(__FILE__,'squads',$where);
  58. if(!empty($search)) {
  59. $error .= $cs_lang[$op_squads['label'].'_exists'] . cs_html_br(1);
  60. }
  61. $where = "clans_id = '" . cs_sql_escape($cs_squads['clans_id']) . "'";
  62. $search = cs_sql_select(__FILE__,'clans','clans_pwd',$where);
  63. if(empty($search['clans_pwd']) OR $search['clans_pwd'] != $clans_pwd) {
  64. $error .= $cs_lang['pwd_wrong'] . cs_html_br(1);
  65. }
  66. }
  67. else {
  68. $cs_squads['clans_id'] = 0;
  69. $cs_squads['games_id'] = 0;
  70. $cs_squads['squads_name'] = '';
  71. $cs_squads['squads_order'] = $op_squads['def_order'];
  72. $cs_squads['squads_pwd'] = '';
  73. }
  74. if(!isset($_POST['submit'])) {
  75. $data['head']['body'] = $cs_lang['errors_here'];
  76. }
  77. elseif(!empty($error)) {
  78. $data['head']['body'] = $error;
  79. }
  80. if(!empty($error) OR !isset($_POST['submit'])) {
  81. foreach($cs_squads AS $key => $value)
  82. $data['squads'][$key] = cs_secure($value);
  83. $data['head']['mod'] = $cs_lang[$op_squads['label'].'s'];
  84. $data['lang']['clan_label'] = $cs_lang[$op_clans['label']];
  85. $cs_clans = cs_sql_select(__FILE__,'clans','clans_name,clans_id',"clans_pwd != ''",'clans_name',0,0);
  86. $data['squads']['clan_sel'] = cs_dropdown('clans_id','clans_name',$cs_clans,$cs_squads['clans_id']);
  87. $data['squads']['clans_pwd'] = $clans_pwd;
  88. if($data['if']['gamesmod'] == TRUE) {
  89. $el_id = 'game_1';
  90. $cs_games = cs_sql_select(__FILE__,'games','games_name,games_id',0,'games_name',0,0);
  91. $games_count = count($cs_games);
  92. $data['squads']['games_sel'] = '';
  93. for($run = 0; $run < $games_count; $run++) {
  94. $sel = $cs_games[$run]['games_id'] == $cs_squads['games_id'] ? 1 : 0;
  95. $data['squads']['games_sel'] .= cs_html_option($cs_games[$run]['games_name'],$cs_games[$run]['games_id'],$sel);
  96. }
  97. $url = 'uploads/games/' . $cs_squads['games_id'] . '.gif';
  98. $data['squads']['games_img'] = cs_html_img($url,0,0,'id="' . $el_id . '"');
  99. }
  100. $matches[1] = $cs_lang['secure_stages'];
  101. $matches[2] = $cs_lang['stage_1'] . $cs_lang['stage_1_text'] . cs_html_br(1);
  102. $matches[2] .= $cs_lang['stage_2'] . $cs_lang['stage_2_text'] . cs_html_br(1);
  103. $matches[2] .= $cs_lang['stage_3'] . $cs_lang['stage_3_text'] . cs_html_br(1);
  104. $matches[2] .= $cs_lang['stage_4'] . $cs_lang['stage_4_text'];
  105. $data['squads']['secure_clip'] = cs_abcode_clip($matches);
  106. $matches[1] = $cs_lang['pic_infos'];
  107. $return_types = '';
  108. foreach($img_filetypes AS $add) {
  109. $return_types .= empty($return_types) ? $add : ', ' . $add;
  110. }
  111. $matches[2] = $cs_lang['max_width'] . $op_squads['max_width'] . ' px' . cs_html_br(1);
  112. $matches[2] .= $cs_lang['max_height'] . $op_squads['max_height'] . ' px' . cs_html_br(1);
  113. $matches[2] .= $cs_lang['max_size'] . cs_filesize($op_squads['max_size']) . cs_html_br(1);
  114. $matches[2] .= $cs_lang['filetypes'] . $return_types;
  115. $data['squads']['picup_clip'] = cs_abcode_clip($matches);
  116. echo cs_subtemplate(__FILE__,$data,'squads','new');
  117. }
  118. else {
  119. $squads_cells = array_keys($cs_squads);
  120. $squads_save = array_values($cs_squads);
  121. cs_sql_insert(__FILE__,'squads',$squads_cells,$squads_save);
  122. $where = "squads_name = '" . cs_sql_escape($cs_squads['squads_name']) . "'";
  123. $getid = cs_sql_select(__FILE__,'squads','squads_id',$where);
  124. $members_cells = array('users_id','squads_id','members_task','members_order','members_admin');
  125. $members_save = array($account['users_id'],$getid['squads_id'],$cs_lang['leader'],1,1);
  126. cs_sql_insert(__FILE__,'members',$members_cells,$members_save);
  127. if(!empty($files['picture']['tmp_name'])) {
  128. $filename = 'picture-' . $getid['squads_id'] . '.' . $extension;
  129. cs_upload('squads',$filename,$files['picture']['tmp_name']);
  130. $cs_squads2['squads_picture'] = $filename;
  131. $squads2_cells = array_keys($cs_squads2);
  132. $squads2_save = array_values($cs_squads2);
  133. cs_sql_update(__FILE__,'squads',$squads2_cells,$squads2_save,$getid['squads_id']);
  134. }
  135. cs_redirect($cs_lang['create_done'],'squads','center');
  136. }