admin-apps.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <?php
  2. //
  3. // This is the main administration page where approvals, rejections, deletions, etc. take place
  4. //
  5. //require_once("cvs-auth.inc");
  6. require_once("email-validation.inc");
  7. require_once("apps.inc");
  8. if( !isset($MAGIC_COOKIE) ) {
  9. Header("Location: http://master.php.net/manage/users.php");
  10. exit;
  11. }
  12. list($user, $pass) = explode(":", base64_decode($MAGIC_COOKIE));
  13. $MAGIC_COOKIE = 'temp';
  14. commonHeader("Applications Administration");
  15. appHeader($the_cat, $the_subcat);
  16. print("
  17. <h1>Applications Administration</h1>
  18. If you just want to browse the applications, you're better off <A href='/apps/'>here</A>.
  19. <hr noshade size=1>
  20. ");
  21. //
  22. // this block contains all the actions the script can take. if we can't authenticate
  23. // or find the app in question we bail out.
  24. //
  25. if( !empty($action) && !empty($app_id) ) {
  26. $res = mysql_query("SELECT * FROM app WHERE id = $app_id");
  27. if( $res ) {
  28. $app = mysql_fetch_object($res);
  29. }else {
  30. print("<p><b>Unable to find app #$app_id.</b></p>");
  31. appFooter();
  32. commonFooter();
  33. exit;
  34. }
  35. switch($action) {
  36. case 'approve':
  37. if( !empty($app->modify_id) ) {
  38. $res = mysql_query("UPDATE app SET status = 'A' WHERE id = $app_id");
  39. $res = mysql_query("DELETE FROM app WHERE id = $app->modify_id");
  40. @unlink(APP_SCREENSHOT_DIR . "/$app->modify_id-thumb.jpg");
  41. @unlink(APP_SCREENSHOT_DIR . "/$app->modify_id.jpg");
  42. }else {
  43. $res = mysql_query("UPDATE app SET status = 'A' WHERE id = $app_id");
  44. }
  45. if( $res ) {
  46. $msg = "Application #$app_id approved.";
  47. }else {
  48. $msg = "Unable to approve application #$app_id.";
  49. }
  50. print("<script language='JavaScript'> alert('$msg'); document.location.href = 'admin-apps.php';</script>");
  51. break;
  52. case 'delete':
  53. $res = mysql_query("DELETE FROM app WHERE id = $app_id");
  54. if( $res ) {
  55. @unlink(APP_SCREENSHOT_DIR . "/$app_id-thumb.jpg");
  56. @unlink(APP_SCREENSHOT_DIR . "/$app_id.jpg");
  57. mail($mailto, "app #$app->id deleted by $user",
  58. "The following application was deleted from the system:\n\n" .
  59. "Name : $app->name\n" .
  60. "Category : " . $appCats[$app->cat_id]->name . "\n" .
  61. "Submitter : $app->submitter\n" .
  62. "Description: $app->blurb\n",
  63. "From: $user@php.net");
  64. $msg = "Application #$app_id deleted.";
  65. }else {
  66. $msg = "Unable to delete application #$app_id.";
  67. }
  68. print("<script language='JavaScript'> alert('$msg'); document.location.href = 'admin-apps.php';</script>");
  69. break;
  70. case 'reject':
  71. $reject_text = "If you are receiving this email it is because your application\n";
  72. $reject_text .= "posted to the on-line PHP-GTK application database has been\n";
  73. $reject_text .= "rejected by one of the editors.\n\n";
  74. $reject_text .= "This is most likely due to the fact that your submission does\n";
  75. $reject_text .= "not appear to be a geniune PHP-GTK application.\n\n";
  76. $res = mysql_query("DELETE FROM app WHERE id = $app_id");
  77. if( $res ) {
  78. @unlink(APP_SCREENSHOT_DIR . "/$app_id-thumb.jpg");
  79. @unlink(APP_SCREENSHOT_DIR . "/$app_id.jpg");
  80. // email the submitter if the address looks reasonable
  81. // uses functions in include/email-validation.inc
  82. $submitter = clean_AntiSPAM($app->submitter);
  83. if (is_emailable_address($submitter)) {
  84. mail($submitter,"app '$app->name' rejected by app editor $user",
  85. $reject_text .
  86. "----- Copy of your submission below -----\n\n" .
  87. "Name : $app->name\n" .
  88. "Category : " . $appCats[$app->cat_id]->name . "\n" .
  89. "Description: $app->blurb\n",
  90. "From: $user@php.net");
  91. }
  92. // email to the list
  93. mail($mailto,"app '$app->name' rejected by app editor $user",
  94. "The following application was rejected from the system:\n\n" .
  95. "Name : $app->name\n" .
  96. "Category : " . $appCats[$app->cat_id]->name . "\n" .
  97. "Description: $app->blurb\n",
  98. "From: $user@php.net");
  99. $msg = "Application #$app_id rejected.";
  100. }else {
  101. $msg = "Unable to reject application #$app_id.";
  102. }
  103. print("<script language='JavaScript'> alert('$msg'); document.location.href = 'admin-apps.php';</script>");
  104. break;
  105. case 'edit':
  106. $form_app = $app;
  107. $form_url = "admin-apps.php";
  108. $form_action = "modify";
  109. $form_submit = "Edit";
  110. include_once("form.php");
  111. appFooter();
  112. commonFooter();
  113. exit;
  114. break;
  115. case 'modify':
  116. $app_old = $app;
  117. if( !empty($_FILES[screenshot][name])
  118. && ereg("^image/", $_FILES[screenshot][type])
  119. && !ereg("gif", $_FILES[screenshot][type])
  120. ) {
  121. $has_new_screenshot = 'Y';
  122. }else {
  123. $has_screenshot = 'N';
  124. }
  125. if( $has_new_screenshot == "Y" || ($had_screenshot == 1 && $delete_screenshot != 1) ) {
  126. $has_screenshot = 'Y';
  127. }
  128. $res = mysql_query("
  129. UPDATE app
  130. SET
  131. status = '$status',
  132. cat_id = $cat_id,
  133. name = '$name',
  134. has_screenshot = '$has_screenshot',
  135. homepage_url = '$homepage_url',
  136. submitter = '$submitter',
  137. blurb = '$blurb'
  138. WHERE id = $app_id
  139. ");
  140. $res = mysql_query("SELECT * FROM app WHERE id = $app_id");
  141. $app = mysql_fetch_object($res);
  142. if( $res == true ) {
  143. if( $delete_screenshot == 1 ) {
  144. @unlink(APP_SCREENSHOT_DIR . "/$app_id.jpg");
  145. @unlink(APP_SCREENSHOT_DIR . "/$app_id-thumb.jpg");
  146. }
  147. if( $has_new_screenshot == 'Y' ) {
  148. handleAppImage($_FILES[screenshot][tmp_name], $app_id);
  149. }
  150. print("<p><b>Application was edited successfully.</b></p>");
  151. // email to the list
  152. mail($mailto,"app '$app->name' modified by app editor $user",
  153. "The following application was modified from this:\n\n" .
  154. "-------------------------------------------------\n" .
  155. "Name : $app_old->name\n" .
  156. "Status : $app_old->status\n" .
  157. "Category : " . $appCats[$app_old->cat_id]->name . "\n" .
  158. "Description: $app_old->blurb\n".
  159. "\n".
  160. "to this:\n\n".
  161. "-------------------------------------------------\n" .
  162. "Name : $app->name\n" .
  163. "Status : $app->status\n" .
  164. "Category : " . $appCats[$app->cat_id]->name . "\n" .
  165. "Description: $app->blurb\n",
  166. "From: $user@php.net");
  167. }else {
  168. print("<p><b><font color='#ff0000'>");
  169. print("There was a problem editing the application.");
  170. print("<br>");
  171. print("Error: (" . mysql_errno() . ") " . mysql_error() );
  172. print("</font></b></p>");
  173. }
  174. print("<table border=0 cellpadding=2 cellspacing=0 width=100%>");
  175. displayApp($app, $the_cat, $the_subcat, $offset);
  176. print("</table>");
  177. appFooter();
  178. commonFooter();
  179. exit;
  180. break;
  181. default:
  182. if( !empty($action) ) {
  183. print("<p><b><font color='#ff0000'>Error: Didn't understand action '$action'.</font></b></p>");
  184. }
  185. }
  186. }
  187. if( empty($the_cat) && empty($the_subcat) && empty($key) ) {
  188. include("pending.php");
  189. }else if( $key == "modified" ) {
  190. include("modified.php");
  191. }else {
  192. include("apps.php");
  193. }
  194. appFooter();
  195. commonFooter();
  196. ?>