PageRenderTime 60ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/pages/maps-local.php

http://adminserv.googlecode.com/
PHP | 192 lines | 168 code | 13 blank | 11 comment | 46 complexity | e8f9e330d83d11ef625f674cd3bf778e MD5 | raw file
  1. <?php
  2. // GAME
  3. if(SERVER_VERSION_NAME == 'TmForever'){
  4. $queries = array(
  5. 'insert' => 'InsertChallenge',
  6. 'add' => 'AddChallenge'
  7. );
  8. }
  9. else{
  10. $queries = array(
  11. 'insert' => 'InsertMap',
  12. 'add' => 'AddMap'
  13. );
  14. }
  15. // ACTIONS
  16. if( isset($_POST['addMap']) && isset($_POST['map']) && count($_POST['map']) > 0 ){
  17. foreach($_POST['map'] as $map){
  18. if( !$client->query($queries['add'], $mapsDirectoryPath.$map) ){
  19. AdminServ::error();
  20. break;
  21. }
  22. }
  23. }
  24. else if( isset($_POST['insertMap']) && isset($_POST['map']) && count($_POST['map']) > 0 ){
  25. foreach($_POST['map'] as $map){
  26. if( !$client->query($queries['insert'], $mapsDirectoryPath.$map) ){
  27. AdminServ::error();
  28. break;
  29. }
  30. }
  31. }
  32. else if( isset($_POST['downloadMap']) && isset($_POST['map']) && count($_POST['map']) > 0 ){
  33. // Si on télécharge plusieurs fichiers, on envoi un zip
  34. if( count($_POST['map']) > 1){
  35. $struct = array();
  36. foreach($_POST['map'] as $map){
  37. $struct[] = $mapsDirectoryPath.$map;
  38. }
  39. $zipError = null;
  40. $zipFileName = 'maps.zip';
  41. if( !Zip::create($zipFileName, $struct, $zipError) ){
  42. AdminServ::error($zipError);
  43. }
  44. else{
  45. File::download($zipFileName);
  46. if( $result = File::delete($zipFileName) !== true ){
  47. AdminServ::error($result);
  48. }
  49. }
  50. }
  51. // Sinon on envoi le fichier seul
  52. else{
  53. File::download($mapsDirectoryPath.$_POST['map'][0]);
  54. }
  55. }
  56. else if( isset($_POST['renameMapValid']) && isset($_POST['map']) && count($_POST['map']) > 0 && isset($_POST['renameMapList']) && count($_POST['renameMapList']) > 0 ){
  57. $i = 0;
  58. foreach($_POST['renameMapList'] as $newMapName){
  59. if( File::rename($mapsDirectoryPath.$_POST['map'][$i], $mapsDirectoryPath.$newMapName) !== true ){
  60. AdminServ::error('Impossible de renommer la map : '.$newMapName);
  61. break;
  62. }
  63. $i++;
  64. }
  65. }
  66. else if( isset($_POST['moveMapValid']) && isset($_POST['moveDirectoryList']) && isset($_POST['map']) && count($_POST['map']) > 0 ){
  67. // Chemin
  68. if($_POST['moveDirectoryList'] == '.'){
  69. $newPath = $mapsDirectoryPath;
  70. }
  71. else{
  72. $newPath = $_POST['moveDirectoryList'];
  73. }
  74. // Déplacement
  75. foreach($_POST['map'] as $map){
  76. if( File::rename($mapsDirectoryPath.$directory.$map, $newPath.$map) !== true ){
  77. AdminServ::error('Impossible de déplacer la map : '.$map);
  78. break;
  79. }
  80. }
  81. }
  82. else if( isset($_POST['deleteMap']) && isset($_POST['map']) && count($_POST['map']) > 0 ){
  83. foreach($_POST['map'] as $map){
  84. if( !File::delete($mapsDirectoryPath.$map) ){
  85. AdminServ::error('Impossible de supprimer la map : '.$map);
  86. break;
  87. }
  88. }
  89. }
  90. // MAPLIST
  91. $sort = null;
  92. if( isset($_GET['sort']) && $_GET['sort'] != null){
  93. $sort = addslashes($_GET['sort']);
  94. }
  95. $mapsList = AdminServ::getLocalMapList($mapsDirectoryPath.$directory, $sort);
  96. // HTML
  97. $client->Terminate();
  98. AdminServUI::getHeader();
  99. ?>
  100. <section class="maps hasMenu hasFolders">
  101. <section class="cadre left menu">
  102. <?php echo AdminServUI::getMenuList(ExtensionConfig::$MAPSMENU); ?>
  103. </section>
  104. <section class="cadre middle folders">
  105. <?php echo $mapsDirectoryList; ?>
  106. </section>
  107. <section class="cadre right local">
  108. <h1>Local</h1>
  109. <div class="title-detail">
  110. <ul>
  111. <li class="path"><?php echo $mapsDirectoryPath.$directory; ?></li>
  112. <li><input type="checkbox" name="checkAll" id="checkAll" value=""<?php if( !is_array($mapsList['lst']) ){ echo ' disabled="disabled"'; } ?> /></li>
  113. </ul>
  114. </div>
  115. <form method="post" action="?p=<?php echo USER_PAGE; if($directory){ echo '&amp;d='.$directory; } ?>">
  116. <div id="maplist">
  117. <table>
  118. <thead>
  119. <tr>
  120. <th class="thleft"><a href="?p=<?php echo USER_PAGE; ?>&amp;sort=name">Map</a></th>
  121. <th><a href="?p=<?php echo USER_PAGE; ?>&amp;sort=env">Environnement</a></th>
  122. <th><a href="?p=<?php echo USER_PAGE; ?>&amp;sort=author">Auteur</a></th>
  123. <th class="thright"></th>
  124. </tr>
  125. <tr class="table-separation"></tr>
  126. </thead>
  127. <tbody>
  128. <?php
  129. $showMapList = null;
  130. // Liste des maps local
  131. if( is_array($mapsList['lst']) && count($mapsList['lst']) > 0 ){
  132. $i = 0;
  133. foreach($mapsList['lst'] as $id => $map){
  134. // Ligne
  135. $showMapList .= '<tr class="'; if($i%2){ $showMapList .= 'even'; }else{ $showMapList .= 'odd'; } $showMapList .= '">'
  136. .'<td class="imgleft"><img src="'.$mapsList['cfg']['path_rsc'].'images/16/map.png" alt="" /><span title="'.$map['FileName'].'">'.$map['Name'].'</span></td>'
  137. .'<td class="imgcenter"><img src="'.$mapsList['cfg']['path_rsc'].'images/env/'.strtolower($map['Environnement']).'.png" alt="" />'.$map['Environnement'].'</td>'
  138. .'<td>'.$map['Author'].'</td>'
  139. .'<td class="checkbox"><input type="checkbox" name="map[]" value="'.$map['FileName'].'" /></td>'
  140. .'</tr>';
  141. $i++;
  142. }
  143. }
  144. else{
  145. $showMapList .= '<tr class="no-line"><td class="center" colspan="4">'.$mapsList['lst'].'</td></tr>';
  146. }
  147. // Affichage
  148. echo $showMapList;
  149. ?>
  150. </tbody>
  151. </table>
  152. </div>
  153. <div class="options">
  154. <div class="fleft">
  155. <span class="nb-line"><?php echo $mapsList['nbm']; ?></span>
  156. </div>
  157. <div class="fright">
  158. <div class="selected-files-label locked">
  159. <span class="selected-files-title">Pour la sélection</span>
  160. <span class="selected-files-count">(0)</span>
  161. <div class="selected-files-option">
  162. <input class="button dark" type="submit" name="deleteMap" id="deleteMap" value="Supprimer" data-confirm="Voulez-vous vraiment supprimer cette sélection ?" />
  163. <input class="button dark" type="button" name="moveMap" id="moveMap" value="Déplacer" />
  164. <input class="button dark" type="button" name="renameMap" id="renameMap" value="Renommer" />
  165. <input class="button dark" type="submit" name="downloadMap" id="downloadMap" value="Télécharger" />
  166. <input class="button dark" type="submit" name="insertMap" id="insertMap" value="Insérer" />
  167. <input class="button dark" type="submit" name="addMap" id="addMap" value="Ajouter" />
  168. </div>
  169. </div>
  170. </div>
  171. <div id="form-rename-map" class="option-form" hidden="hidden" data-cancel="Annuler" data-rename="Renommer"></div>
  172. <div id="form-move-map" class="option-form" hidden="hidden" data-cancel="Annuler" data-move="Déplacer" data-inthefolder="dans le dossier :" data-root="Racine"></div>
  173. </div>
  174. </form>
  175. </section>
  176. </section>
  177. <?php
  178. AdminServUI::getFooter();
  179. ?>