PageRenderTime 28ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/players/manage.php

https://github.com/wolas/advertball
PHP | 177 lines | 162 code | 12 blank | 3 comment | 8 complexity | aa040d0fc63f62ecc3f8763fa561add8 MD5 | raw file
  1. <?php
  2. ob_start();
  3. require_once("../../includes/initialize.php");
  4. if(!$session->is_admin()){redirect_to("../session/login.php");}
  5. $team = Team::find_by_id($_GET['id']);
  6. if(isset($_POST['commit'])){
  7. $player = new Player();
  8. $player->name = $_POST['name'];
  9. $player->number = $_POST['number'];
  10. $player->surname = $_POST['surname'];
  11. $player->email = $_POST['email'];
  12. $player->team_id = $team->id;
  13. if(!$player->save()){
  14. $message = "Unable to insert data";
  15. }
  16. /* upload files only when player is valid */
  17. $_files;
  18. $upload_dir = SITE_ROOT . DS . "uploads" . DS . "team_" . $team->id . DS;
  19. mkdir($upload_dir);
  20. while(list($key,$value) = each($_FILES['userfile']['name'])){
  21. if(!empty($value)){
  22. $extension = substr($value, strrpos($value, '.') + 1);
  23. $filename = "player_" . $player->id . "_" . $key . "." . $extension;
  24. $_files .= str_replace(" ","_",$filename) . ":";
  25. $filename= $upload_dir . str_replace(" ","_",$filename);// replace blank space with '_'
  26. move_uploaded_file($_FILES['userfile']['tmp_name'][$key],$filename);
  27. }
  28. }
  29. //retrieve file uploaded file names
  30. list($_photo, $_payslip) = explode(":", $_files);
  31. //add file name to player fields
  32. $player->photo = $_photo;
  33. $player->payslip = $_payslip;
  34. $player->save(); // because we modified it
  35. redirect_to("manage.php?id=" . $team->id);
  36. }
  37. ?>
  38. <html xmlns="http://www.w3.org/1999/xhtml">
  39. <head>
  40. <title>Advertball - Giocatore nuovo</title>
  41. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  42. <meta http-equiv="Content-Language" content="it"/>
  43. <meta name="script" http-equiv="Content-Script-Type" content="text/javascript"/>
  44. <meta name="script" http-equiv="Content-Style-Type" content="text/css"/>
  45. <meta name="description" content="Advertball - Il torneo di calcio a 7 dei profesionisti della comunicazione"/>
  46. <meta name="keywords" content="Y&R, Young&Rubicam Brands, VML, digital, Adidas, Birra Moretti, Fondazione Corti, ADC Group, Assocomunicazione, torneo a 7, torneo aziendale, CSI, Advertball, ball, comunicazione, calcio, agenzia di comunicazione, Actimel, Palmolive, Cisalfa Sport"/>
  47. <meta name="distribution" content="Global"/>
  48. <link rel="shortcut icon" href="../../images/icon.ico">
  49. <link rel="stylesheet" type="text/css" href="../../css/style.css" media="screen"/>
  50. <link rel="stylesheet" type="text/css" href="../../css/admin.css" media="screen"/>
  51. <script src="../../js/yav.js"></script>
  52. <script src="../../js/yav-config.js"></script>
  53. <script>
  54. function check_photo() {
  55. var msg;
  56. (document.forms[0].photo.value == "" ) ? msg = "Photo is required" : msg = null;
  57. return msg;
  58. }
  59. function check_payslip() {
  60. var msg;
  61. (document.forms[0].payslip.value == "" ) ? msg = "Payslip is required" : msg = null;
  62. return msg;
  63. }
  64. var rules=new Array();
  65. rules[0]='name|required';
  66. rules[1]='surname|required';
  67. rules[2]='email|email';
  68. rules[3]='email|required';
  69. rules[4]='payslip|required';
  70. rules[5]='photo|custom|check_photo()';
  71. rules[6]='payslip|custom|check_payslip()';
  72. rules[7]='number|required';
  73. </script>
  74. </head>
  75. <body>
  76. <table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
  77. <tr>
  78. <td align="center" valign="middle">
  79. <div id="page">
  80. <div id="ctnsx">
  81. <h1><a href="../../index.html"><span>ADVERTBALL</span></a></h1>
  82. <ul id="menu">
  83. <li><a href="../agencies/index.php" class="menu_blank">Agencies</a></li>
  84. <li><a href="../teams/index.php" class="menu_blank">Teams</a></li>
  85. <li><a href="../matches/index.php" class="menu_blank">Matches</a></li>
  86. </ul>
  87. </div>
  88. <div id="ctndx">
  89. <h2><img src="../../images/players.gif" alt="Modifica Squadra" /></h2>
  90. <div id="scroll-container">
  91. <div id="content">
  92. <?php if(count($team->players()) != 15){ ?>
  93. <div style="border:1px solid #cccccc; padding:5px;width: 500px;">
  94. <form style="height: 190px;" name="_form" action="<?php echo $_SERVER['php_self']?>" method="post" onSubmit="return yav.performCheck('_form', rules, 'inline');" enctype='multipart/form-data'>
  95. <table class="edit_table">
  96. <tr>
  97. <td>Name</td>
  98. <td><input style="width:200px;" id="name" name="name" size="15" maxlength="30" type="text" value="<?php echo $player->name;?>"/></td>
  99. <td class="right_column"><span id="errorsDiv_name"></span></td>
  100. </tr>
  101. <tr>
  102. <td>Surname</td>
  103. <td><input style="width:200px;" id="surname" name="surname" size="15" maxlength="30" type="text" value="<?php echo $player->surname;?>"/></td>
  104. <td class="right_column"><span id="errorsDiv_surname"></span></td>
  105. </tr>
  106. <tr>
  107. <td>Number</td>
  108. <td><input style="width:200px;" id="number" name="number" size="15" maxlength="30" type="text" value="<?php echo $player->number;?>"/></td>
  109. <td class="right_column"><span id="errorsDiv_number"></span></td>
  110. </tr>
  111. <tr>
  112. <td>Email</td>
  113. <td ><input style="width:200px;" id="email" name="email" size="15" maxlength="30" type="text" value="<?php echo $player->email;?>"/></td>
  114. <td class="right_column"><span id="errorsDiv_email"></span></td>
  115. </tr>
  116. <tr><td colspan="3">&nbsp;</td></tr>
  117. <tr>
  118. <td>Photo</td>
  119. <td><input id="photo" style="width:200px;" type="file" size="20" name="userfile[]"></td>
  120. <td class="right_column"><span id="errorsDiv_photo"></span></td>
  121. </tr>
  122. <tr>
  123. <td>Busta</td>
  124. <td><input id="payslip" style="width:200px;" type="file" size="20" name="userfile[]"></td>
  125. <td class="right_column"><span id="errorsDiv_payslip"></span></td>
  126. </tr>
  127. <tr>
  128. <td style="text-align:left;"><a href="../teams/show.php?id=<?php echo $team->id?>"><img src="../../images/btn_back.gif" alt="indietro" /></a></td>
  129. <td><input id="commit" name="commit" class="send" type="submit" value="" /></td>
  130. </tr>
  131. </table>
  132. </form>
  133. </div>
  134. <?php } ?>
  135. <?php $index = 0 ?>
  136. <div style="height:240px;">
  137. <?php foreach ($team->players() as $player) {?>
  138. <?php $index += 1 ?>
  139. <a href="show.php?id=<?php echo $player->id ?>">
  140. <div class="player_widget" style="background-image: url('../../images/bg_players<?php echo ($index % 2) ? '1' : '2' ?>.gif');">
  141. <span style="vertical-align:middle;">
  142. <div style="padding:10px 5px 10px 10px;float:left;vertical-align:middle;display:inline;">
  143. <img src="../../uploads/<?php echo $player->photo_url() ?>" width="30px" height="30px"/>
  144. </div>
  145. <div style="padding:10px 5px 10px 10px;float:left;display:inline;vertical-align:middle;">
  146. <?php echo $player->name . " " . $player->surname ?>
  147. <br/>
  148. <? echo $player->email ?>
  149. </div>
  150. <div style="height:1px;clear:both;"></div>
  151. </div>
  152. </a>
  153. <?php }?>
  154. </div>
  155. </div>
  156. </div>
  157. <div id="footer"><a href="../session/logout.php">Logout</a> &bull; <a href="../../pages/players/manage.php?id=<?php echo $team->id ?>">Public Site</a></div>
  158. </div>
  159. </div>
  160. </td>
  161. </tr>
  162. </table>
  163. </body>
  164. </html>
  165. <?php ob_end_flush();?>