PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/php/console/controllers/street_team_controller.php

http://github.com/newscloud/open-social-media-toolkit
PHP | 724 lines | 551 code | 95 blank | 78 comment | 141 complexity | 50ab779e071e4e34a6d0e6e45dfe6607 MD5 | raw file
  1. <?php
  2. Class Street_teamController extends AppController {
  3. var $name = 'Street_team';
  4. public function feature_panel() {
  5. $this->render('not_implemented');
  6. }
  7. /****************************************************************
  8. * Leaders section
  9. ***************************************************************/
  10. public function licensePlateEligibleLeaders() {
  11. $week=12;
  12. //$week = $_GET['week'];
  13. $leaders=array();
  14. $leadersQ = $this->db->query(
  15. "SELECT name, cachedPointsEarned AS pointTotal, eligibility, fbId,User.userid
  16. FROM User,UserInfo
  17. WHERE UserInfo.userid=User.userid
  18. AND User.isBlocked=0 AND cachedPointsEarned>0
  19. AND User.userid NOT IN(select userid1 from Log where action='wonPrize' AND itemid=20)
  20. ". //(SELECT userid FROM Orders WHERE prizeid=20); //
  21. "ORDER BY eligibility, cachedPointsEarned DESC;");
  22. while ($row=mysql_fetch_assoc($leadersQ))
  23. {
  24. $leaders []= $row;
  25. }
  26. $this->set('leaders', $leaders);
  27. $this->set('week', $week);
  28. $this->set('action_title', "<h2>Members from up to the end of week $week that were not awarded license plate frames</h2>");
  29. $this->render('leaders');
  30. }
  31. public function leaders() {
  32. require_once(PATH_CONSOLE.'/helpers/application_helper.php');
  33. // ::TODO:: FIX THIS BULLSHIT
  34. //echo '<pre>'.print_r($this->db, true) .'</pre>';
  35. disp_header();
  36. echo '<script type="text/javascript">';
  37. require(PATH_CONSOLE.'/views/leaders.js');
  38. echo '</script>';
  39. $leadersQ = $this->db->query(
  40. "SELECT (DATE(weekOf)) AS week, WEEK(weekOf,1) as weekNum, name, pointTotal, eligibility, fbId,User.userid
  41. FROM WeeklyScores, User,UserInfo
  42. WHERE UserInfo.userid=WeeklyScores.userid
  43. AND User.userid=WeeklyScores.userid AND User.isBlocked=0 AND pointTotal>0
  44. ORDER BY weekOf,eligibility, pointTotal DESC;");
  45. while ($row=mysql_fetch_assoc($leadersQ))
  46. {
  47. $leaders []= $row;
  48. }
  49. require(PATH_CONSOLE.'/views/street_team/leaders.php');
  50. $leaders=array();
  51. $leadersQ = $this->db->query(
  52. "SELECT name, cachedPointsEarned AS pointTotal, eligibility, fbId,User.userid
  53. FROM User,UserInfo
  54. WHERE UserInfo.userid=User.userid
  55. AND User.isBlocked=0 AND cachedPointsEarned>0
  56. ORDER BY eligibility, cachedPointsEarned DESC LIMIT 250;"); // TODO: may shorten this after first week scoring
  57. while ($row=mysql_fetch_assoc($leadersQ))
  58. {
  59. $leaders []= $row;
  60. }
  61. //$this->set('leaders', $leaders);
  62. //$this->set('action_title', '<h2>All-time leaders</h2>');
  63. require(PATH_CONSOLE.'/views/street_team/leaders.php');
  64. disp_footer();
  65. exit;
  66. }
  67. public function assign_prize() {
  68. /*
  69. if ((isset($_GET['id']) && preg_match('/^[0-9]+$/', $_GET['id']))
  70. OR (isset($_GET['multiple']))) {
  71. $userid = $_GET['id'];
  72. } else {
  73. set_flash(array('error' => "Invalid $group -- $action -- userid: $userid."));
  74. redirect(url_for('street_team', 'leaders'));
  75. }
  76. */
  77. // process single userid or extract multiple userids
  78. if (!isset($_GET['multiple']))
  79. {
  80. $userid_array = array($userid);
  81. } else
  82. {
  83. $userid_array = array();
  84. foreach ($_POST AS $val => $id)
  85. {
  86. if (stristr($val,'check_')!==false)
  87. {
  88. $userid_array []=$id;
  89. }
  90. }
  91. }
  92. // make unique
  93. $userid_array = array_unique($userid_array);
  94. $userids = implode(' ,', $userid_array);
  95. $this->render();
  96. }
  97. public function award_prize() {
  98. if (isset($_POST['prizeid']) && preg_match('/^[0-9]+$/', $_POST['prizeid'])) {
  99. $prizeid = $_POST['prizeid'];
  100. } else {
  101. set_flash(array('error' => "Invalid $group -- $action -- prizeid: $prizeid."));
  102. redirect(url_for('street_team', 'leaders'));
  103. }
  104. if (isset($_POST['userids']) /*&& preg_match('/^[0-9]+$/', $_POST['userids'])*/) {
  105. $userids = $_POST['userids'];
  106. } else {
  107. set_flash(array('error' => "Invalid $group -- $action -- userid: $userid."));
  108. redirect(url_for('street_team', 'leaders'));
  109. }
  110. // actually update the database
  111. disp_header();
  112. //echo $message;
  113. // echo '<pre>' . print_r($_POST,true) . '</pre>';
  114. require('views/award_prize.php');
  115. disp_footer();
  116. }
  117. /****************************************************************
  118. * Challenges section
  119. ***************************************************************/
  120. public function challenges() {
  121. $challenges = $this->db->load_all();
  122. $this->set('challenges', $challenges);
  123. $this->render();
  124. }
  125. public function view_challenge() {
  126. $id = $this->params['id'];
  127. if ($id === 0) {
  128. set_flash(array('error' => "Sorry no current challenge for id: $id"));
  129. redirect(url_for($this->name, 'challenges'));
  130. }
  131. if (($challenge = $this->db->load($id))) {
  132. $this->set('challenge', $challenge);
  133. $this->render();
  134. } else {
  135. set_flash(array('error' => "Sorry no current challenge for id: $id"));
  136. redirect(url_for('street_team', 'challenges'));
  137. }
  138. }
  139. public function challenge_detail_report() {
  140. $id = $this->params['id'];
  141. if ($id === 0) {
  142. set_flash(array('error' => "Sorry no current challenge for id: $id"));
  143. redirect(url_for($this->name, 'challenges'));
  144. }
  145. if (($challenge = $this->db->load($id))) {
  146. //$results = $this->db->query("SELECT * FROM ChallengesCompleted WHERE challengeid = {$challenge['id']}");
  147. //$results = $this->db->query("SELECT userid, dateSubmitted, concat(evidence) as evidence,status, pointsAwarded, concat(comments) as comments FROM ChallengesCompleted WHERE challengeid = {$challenge['id']}");
  148. $results = $this->db->query("select challengeid,Challenges.title,concat(evidence) as evidence,ChallengesCompleted.status,dateSubmitted,pointsAwarded,concat(comments) as comments,concat('http://host.newscloud.com/sites/climate/facebook/uploads/submissions/',localFilename) as imgPath,embedCode as videoPath from ((ChallengesCompleted LEFT JOIN Challenges ON Challenges.id=ChallengesCompleted.challengeid) LEFT JOIN Photos ON ChallengesCompleted.id=Photos.challengeCompletedId) LEFT JOIN Videos ON ChallengesCompleted.id=Videos.challengeCompletedId WHERE ChallengesCompleted.challengeid = {$challenge['id']} ORDER BY dateSubmitted");
  149. $completed_challenges = array();
  150. while (($cc = mysql_fetch_assoc($results)) !== false)
  151. $completed_challenges[] = $cc;
  152. $this->set('challenge', $challenge);
  153. $this->set('completed_challenges', $completed_challenges);
  154. $this->render();
  155. } else {
  156. set_flash(array('error' => "Sorry no current challenge for id: $id"));
  157. redirect(url_for('street_team', 'challenges'));
  158. }
  159. }
  160. public function new_challenge() {
  161. $this->render();
  162. }
  163. public function create_challenge() {
  164. if (isset($_POST['challenge']['title'])) {
  165. //$id = $this->db->insert($_POST['challenge']);
  166. if (($id = $this->db->insert($_POST['challenge'])) > 0) {
  167. //if (preg_match('/^[0-9]+$/', $id)) {
  168. set_flash(array('notice' => 'Successfully created challenge!'));
  169. redirect(url_for('street_team', 'view_challenge', $id));
  170. } else {
  171. set_flash(array('error' => 'Could not create your challenge! Please try again. '.$id));
  172. redirect(url_for('street_team', 'new_challenge'));
  173. }
  174. } else {
  175. set_flash(array('error' => 'Form data not submitted properly, please try again.'));
  176. redirect(url_for('street_team', 'new_challenge'));
  177. }
  178. }
  179. public function modify_challenge() {
  180. $id = $this->params['id'];
  181. if ($id === 0) {
  182. set_flash(array('error' => "Sorry no current challenge for id: $id"));
  183. redirect(url_for($this->name, 'challenges'));
  184. }
  185. if (($challenge = $this->db->load($id))) {
  186. $this->set('challenge', $challenge);
  187. $this->render();
  188. } else {
  189. set_flash(array('error' => "Sorry no current challenge for id: $id"));
  190. redirect(url_for('street_team', 'challenges'));
  191. }
  192. }
  193. public function update_challenge() {
  194. if (isset($_POST['challenge']['id']) && preg_match('/^[0-9]+$/', $_POST['challenge']['id'])) {
  195. $id = $_POST['challenge']['id'];
  196. } else {
  197. set_flash(array('error' => "Invalid $group -- $action -- id: $id."));
  198. redirect(url_for('street_team', 'challenges'));
  199. }
  200. if (isset($_POST['challenge']['title'])) {
  201. // djm: take care of image upload /////////
  202. $newthumb =
  203. handle_image_upload('thumbnail', "prize_{$_POST['challenge']['id']}_");
  204. if ($newthumb)
  205. $_POST['challenge']['thumbnail'] = $newthumb;
  206. ///////////////////////////////////////////
  207. if (($result = $this->db->update($_POST['challenge'])) == 1) {
  208. set_flash(array('notice' => 'Successfully updated challenge.'));
  209. redirect(url_for('street_team', 'view_challenge', $id));
  210. } else {
  211. set_flash(array('error' => 'Could not update your challenge! Please try again. '.$result));
  212. redirect(url_for('street_team', 'modify_challenge', $id));
  213. }
  214. } else {
  215. set_flash(array('error' => 'Form data not submitted properly, please try again.'));
  216. redirect(url_for('street_team', 'modify_challenge', $id));
  217. }
  218. }
  219. public function destroy_challenge() {
  220. $id = $this->params['id'];
  221. if ($id === 0) {
  222. set_flash(array('error' => "Sorry no current challenge for id: $id"));
  223. redirect(url_for($this->name, 'challenges'));
  224. }
  225. if (($result = $this->db->delete($id)) == 1) {
  226. set_flash(array('notice' => 'Successfully deleted challenge.'));
  227. redirect(url_for('street_team', 'challenges'));
  228. } else {
  229. set_flash(array('error' => 'Could not delete challenge. Please try again. '.$result));
  230. redirect(url_for('street_team', 'challenges'));
  231. }
  232. }
  233. /****************************************************************
  234. * Prizes section
  235. ***************************************************************/
  236. public function prizes() {
  237. $prizes = $this->db->load_all();
  238. $this->set('prizes', $prizes);
  239. $this->render();
  240. }
  241. public function view_prize() {
  242. $id = $this->params['id'];
  243. if ($id === 0) {
  244. set_flash(array('error' => "Sorry no current prize for id: $id"));
  245. redirect(url_for($this->name, 'prizes'));
  246. }
  247. if (($prize = $this->db->load($id))) {
  248. $this->set('prize', $prize);
  249. $this->render();
  250. } else {
  251. set_flash(array('error' => "Sorry no current prize for id: $id"));
  252. redirect(url_for('street_team', 'prizes'));
  253. }
  254. }
  255. public function new_prize() {
  256. $this->render();
  257. }
  258. public function create_prize() {
  259. if (isset($_POST['prize']['title'])) {
  260. //$id = $this->db->insert($_POST['prize']);
  261. $newthumb = handle_image_upload('thumbnail', "prize_".time());
  262. if ($newthumb)
  263. $_POST['prize']['thumbnail'] = $newthumb;
  264. if (($id = $this->db->insert($_POST['prize'])) > 0) {
  265. set_flash(array('notice' => 'Successfully created prize!'));
  266. redirect(url_for('street_team', 'view_prize', $id));
  267. } else {
  268. set_flash(array('error' => 'Could not create your prize! Please try again. '.$id));
  269. redirect(url_for('street_team', 'new_prize'));
  270. }
  271. } else {
  272. set_flash(array('error' => 'Form data not submitted properly, please try again.'));
  273. redirect(url_for('street_team', 'new_prize'));
  274. }
  275. }
  276. public function modify_prize() {
  277. $id = $this->params['id'];
  278. if ($id === 0) {
  279. set_flash(array('error' => "Sorry no current prize for id: $id"));
  280. redirect(url_for($this->name, 'prizes'));
  281. }
  282. if (($prize = $this->db->load($id))) {
  283. $this->set('prize', $prize);
  284. $this->render();
  285. } else {
  286. set_flash(array('error' => "Sorry no current prize for id: $id"));
  287. redirect(url_for('street_team', 'prizes'));
  288. }
  289. }
  290. public function update_prize() {
  291. $id = $this->params['id'];
  292. if ($id === 0) {
  293. set_flash(array('error' => "Sorry no current prize for id: $id"));
  294. redirect(url_for($this->name, 'prizes'));
  295. }
  296. if (isset($_POST['prize']['title'])) {
  297. // djm: take care of image upload ///
  298. $newthumb =
  299. handle_image_upload('thumbnail', "prize_{$_POST['prize']['id']}_");
  300. if ($newthumb)
  301. $_POST['prize']['thumbnail'] = $newthumb;
  302. /////////////////////////////////////
  303. if (($result = $this->db->update($_POST['prize'])) == 1) {
  304. set_flash(array('notice' => 'Successfully updated prize.'));
  305. redirect(url_for('street_team', 'view_prize', $id));
  306. } else {
  307. set_flash(array('error' => 'Could not update your prize! Please try again. '.$result));
  308. redirect(url_for('street_team', 'modify_prize', $id));
  309. }
  310. } else {
  311. set_flash(array('error' => 'Form data not submitted properly, please try again.'));
  312. redirect(url_for('street_team', 'modify_prize', $id));
  313. }
  314. }
  315. public function destroy_prize() {
  316. $id = $this->params['id'];
  317. if ($id === 0) {
  318. set_flash(array('error' => "Sorry no current prize for id: $id"));
  319. redirect(url_for($this->name, 'prizes'));
  320. }
  321. if (($result = $this->db->delete($id)) == 1) {
  322. set_flash(array('notice' => 'Successfully deleted prize.'));
  323. redirect(url_for('street_team', 'prizes'));
  324. } else {
  325. set_flash(array('error' => 'Could not delete prize. Please try again. '.$result));
  326. redirect(url_for('street_team', 'prizes'));
  327. }
  328. }
  329. public function winners() {
  330. $this->render('not_implemented');
  331. }
  332. /****************************************************************
  333. * Orders Section
  334. ***************************************************************/
  335. public function orders() {
  336. $orders = $this->db->load_all();
  337. $this->set('orders', $orders);
  338. $this->render();
  339. }
  340. public function view_order() {
  341. $id = $this->params['id'];
  342. if ($id === 0) {
  343. set_flash(array('error' => "Sorry no current order for id: $id"));
  344. redirect(url_for($this->name, 'orders'));
  345. }
  346. if (($order = $this->db->load($id))) {
  347. $this->set('order', $order);
  348. $this->render();
  349. } else {
  350. set_flash(array('error' => "Sorry no current order for id: $id"));
  351. redirect(url_for('street_team', 'orders'));
  352. }
  353. }
  354. public function new_order() {
  355. $this->render();
  356. }
  357. public function create_order() {
  358. if (isset($_POST['order']['userid'])) {
  359. //$id = $this->db->insert($_POST['order']);
  360. if (($id = $this->db->insert($_POST['order'])) > 0) {
  361. //if (preg_match('/^[0-9]+$/', $id)) {
  362. set_flash(array('notice' => 'Successfully created order!'));
  363. redirect(url_for('street_team', 'view_order', $id));
  364. } else {
  365. set_flash(array('error' => 'Could not create your order! Please try again. '.$id));
  366. redirect(url_for('street_team', 'new_order'));
  367. }
  368. } else {
  369. set_flash(array('error' => 'Form data not submitted properly, please try again.'));
  370. redirect(url_for('street_team', 'new_order'));
  371. }
  372. }
  373. public function modify_order() {
  374. $id = $this->params['id'];
  375. if ($id === 0) {
  376. set_flash(array('error' => "Sorry no current order for id: $id"));
  377. redirect(url_for($this->name, 'orders'));
  378. }
  379. if (($order = $this->db->load($id))) {
  380. $this->set('order', $order);
  381. $this->render();
  382. } else {
  383. set_flash(array('error' => "Sorry no current order for id: $id"));
  384. redirect(url_for('street_team', 'orders'));
  385. }
  386. }
  387. public function update_order() {
  388. if (isset($_POST['order']['id']) && preg_match('/^[0-9]+$/', $_POST['order']['id'])) {
  389. $id = $_POST['order']['id'];
  390. } else {
  391. set_flash(array('error' => "Invalid $group -- $action -- id: $id."));
  392. redirect(url_for('street_team', 'orders'));
  393. }
  394. if (isset($_POST['order']['userid'])) {
  395. if (($result = $this->db->update($_POST['order'])) == 1) {
  396. set_flash(array('notice' => 'Successfully updated order.'));
  397. redirect(url_for('street_team', 'view_order', $id));
  398. } else {
  399. set_flash(array('error' => 'Could not update your order! Please try again. '.$result));
  400. redirect(url_for('street_team', 'modify_order', $id));
  401. }
  402. } else {
  403. set_flash(array('error' => 'Form data not submitted properly, please try again.'));
  404. redirect(url_for('street_team', 'modify_order', $id));
  405. }
  406. }
  407. public function destroy_order() {
  408. $id = $this->params['id'];
  409. if ($id === 0) {
  410. set_flash(array('error' => "Sorry no current order for id: $id"));
  411. redirect(url_for($this->name, 'orders'));
  412. }
  413. if (($result = $this->db->delete($id)) == 1) {
  414. set_flash(array('notice' => 'Successfully deleted order.'));
  415. redirect(url_for('street_team', 'orders'));
  416. } else {
  417. set_flash(array('error' => 'Could not delete order. Please try again. '.$result));
  418. redirect(url_for('street_team', 'orders'));
  419. }
  420. }
  421. /****************************************************************
  422. * Completed Challenges Section
  423. ***************************************************************/
  424. public function completed_challenges() {
  425. require_once(PATH_CONSOLE.'/helpers/application_helper.php');
  426. // major hacks
  427. function isAutomatic($cc) { return $cc['evidence'] == 'Automatic!'; } // bit of a hack, depends on all auto challenges setting evidence to 'Automatic!'
  428. function isNotAutomatic($cc) { return !isAutomatic($cc); }
  429. function awaitingReview($cc) { return $cc['status']=='submitted' && isNotAutomatic($cc); }
  430. function isReviewed($cc) { return $cc['status']=='awarded' || $cc['status']=='rejected' || isAutomatic($cc); }
  431. //$cc_types = array( 'Submission' => array_filter($completed_challenges, 'isNotAutomatic'),
  432. // 'Automatic' => array_filter($completed_challenges, 'isAutomatic'));
  433. disp_header();
  434. // haaacks - should really join on Challenge type rather than rely on evidence='Automatic!'
  435. echo '<h1>Submission Challenges</h1>';
  436. $completed_challenges = $this->db->load_all("SELECT * FROM ChallengesCompleted WHERE status='submitted' AND evidence!='Automatic!' ORDER BY dateSubmitted DESC LIMIT 1000");
  437. require(PATH_CONSOLE.'/views/street_team/completed_challenges.php');
  438. echo '<h1>Auto Challenges</h1>';
  439. $completed_challenges = $this->db->load_all("SELECT * FROM ChallengesCompleted WHERE evidence='Automatic!' ORDER BY dateSubmitted DESC LIMIT 100");
  440. require(PATH_CONSOLE.'/views/street_team/completed_challenges.php');
  441. disp_footer();
  442. exit;
  443. }
  444. public function view_completed_challenge() {
  445. $id = $this->params['id'];
  446. if ($id === 0) {
  447. set_flash(array('error' => "Sorry no current completed challenge for id: $id"));
  448. redirect(url_for($this->name, 'completed_challenges'));
  449. }
  450. if (($completed_challenge = $this->db->load($id))) {
  451. $this->set('completed_challenge', $completed_challenge);
  452. $this->render();
  453. } else {
  454. set_flash(array('error' => "Sorry no current completed_challenge for id: $id"));
  455. redirect(url_for('street_team', 'completed_challenges'));
  456. }
  457. }
  458. public function new_completed_challenge() {
  459. $this->render();
  460. }
  461. public function create_completed_challenge() {
  462. if (isset($_POST['completed_challenge']['userid'])) {
  463. //$id = $this->db->insert($_POST['completed_challenge']);
  464. if (($id = $this->db->insert($_POST['completed_challenge'])) > 0) {
  465. //if (preg_match('/^[0-9]+$/', $id)) {
  466. set_flash(array('notice' => 'Successfully created completed_challenge!'));
  467. redirect(url_for('street_team', 'view_completed_challenge', $id));
  468. } else {
  469. set_flash(array('error' => 'Could not create your completed_challenge! Please try again. '.$id));
  470. redirect(url_for('street_team', 'new_completed_challenge'));
  471. }
  472. } else {
  473. set_flash(array('error' => 'Form data not submitted properly, please try again.'));
  474. redirect(url_for('street_team', 'new_completed_challenge'));
  475. }
  476. }
  477. public function modify_completed_challenge() {
  478. $id = $this->params['id'];
  479. if ($id === 0) {
  480. set_flash(array('error' => "Sorry no current completed challenge for id: $id"));
  481. redirect(url_for($this->name, 'completed_challenges'));
  482. }
  483. if (($completed_challenge = $this->db->load($id))) {
  484. $this->set('completed_challenge', $completed_challenge);
  485. $this->render();
  486. } else {
  487. set_flash(array('error' => "Sorry no current completed_challenge for id: $id"));
  488. redirect(url_for('street_team', 'completed_challenges'));
  489. }
  490. }
  491. public function update_completed_challenge() {
  492. if (isset($_POST['completed_challenge']['id']) && preg_match('/^[0-9]+$/', $_POST['completed_challenge']['id'])) {
  493. $id = $_POST['completed_challenge']['id'];
  494. } else {
  495. set_flash(array('error' => "Invalid $group -- $action -- id: $id."));
  496. redirect(url_for('street_team', 'completed_challenges'));
  497. }
  498. if (isset($_POST['completed_challenge']['userid'])) {
  499. if (($result = $this->db->update($_POST['completed_challenge'])) == 1) {
  500. set_flash(array('notice' => 'Successfully updated completed_challenge.'));
  501. redirect(url_for('street_team', 'view_completed_challenge', $id));
  502. } else {
  503. set_flash(array('error' => 'Could not update your completed_challenge! Please try again. '.$result));
  504. redirect(url_for('street_team', 'modify_completed_challenge', $id));
  505. }
  506. } else {
  507. set_flash(array('error' => 'Form data not submitted properly, please try again.'));
  508. redirect(url_for('street_team', 'modify_completed_challenge', $id));
  509. }
  510. }
  511. public function destroy_completed_challenge() {
  512. $id = $this->params['id'];
  513. if ($id === 0) {
  514. set_flash(array('error' => "Sorry no current completed challenge for id: $id"));
  515. redirect(url_for($this->name, 'completed_challenges'));
  516. }
  517. if (($result = $this->db->delete($id)) == 1) {
  518. set_flash(array('notice' => 'Successfully deleted completed_challenge.'));
  519. redirect(url_for('street_team', 'completed_challenges'));
  520. } else {
  521. set_flash(array('error' => 'Could not delete completed_challenge. Please try again. '.$result));
  522. redirect(url_for('street_team', 'completed_challenges'));
  523. }
  524. }
  525. public function approve_completed_challenge() { // slight hack, since this now handles rejection as well
  526. if (isset($_POST['completed_challenge']['id']) && preg_match('/^[0-9]+$/', $_POST['completed_challenge']['id']))
  527. {
  528. $id = $_POST['completed_challenge']['id'];
  529. } else
  530. {
  531. set_flash(array('error' => "Invalid $group -- $action -- id: $id."));
  532. redirect(url_for('street_team', 'completed_challenges'));
  533. }
  534. if ($_POST['reject']) // user pressed reject button
  535. {
  536. /*
  537. *
  538. //$_POST['completed_challenge[status]']='rejected'; // set status to rejected
  539. // update to set comment text
  540. if (($result = $this->db->update($_POST['completed_challenge'])) == 1)
  541. {
  542. */
  543. // grrr russell
  544. require_once( PATH_CORE .'/classes/challenges.class.php');
  545. $cct = new ChallengeCompletedTable();
  546. $cc = $cct->getRowObject();
  547. if ($cc->load($id))
  548. {
  549. $cc->status='rejected';
  550. $cc->update();
  551. set_flash(array('notice' => "Challenge submission $id rejected."));
  552. redirect(url_for('street_team', 'view_completed_challenge', $id));
  553. } else {
  554. set_flash(array('error' => 'Could not update your completed_challenge! Please try again. '.$result));
  555. redirect(url_for('street_team', 'modify_completed_challenge', $id));
  556. }
  557. } elseif (isset($_POST['pointsAwarded'])) // user presumably pressed approve and assigned nonzero points
  558. {
  559. // update to set comment text
  560. if (($result = $this->db->update($_POST['completed_challenge'])) == 1)
  561. {
  562. } else {
  563. set_flash(array('error' => 'Could not update your completed_challenge! Please try again. '.$result));
  564. redirect(url_for('street_team', 'modify_completed_challenge', $id));
  565. }
  566. // djm:
  567. require_once( PATH_CORE .'/classes/challenges.class.php');
  568. $cct = new ChallengeCompletedTable();
  569. $cct->approveChallenge($id, $_POST['pointsAwarded'], &$code);
  570. /*
  571. if (($result = $this->db->update($_POST['completed_challenge'])) == 1)
  572. {
  573. set_flash(array('notice' => 'Successfully updated completed_challenge.'));
  574. redirect(url_for('street_team', 'view_completed_challenge', $id));
  575. } else
  576. {
  577. set_flash(array('error' => 'Could not update your completed_challenge! Please try again. '.$result));
  578. redirect(url_for('street_team', 'review_completed_challenge', $id));
  579. }*/
  580. set_flash(array('notice' => $code));
  581. redirect(url_for('street_team', 'view_completed_challenge', $id));
  582. } else
  583. {
  584. set_flash(array('error' => 'Form data not submitted properly, please try again.'));
  585. redirect(url_for('street_team', 'view_completed_challenge', $id));
  586. }
  587. }
  588. /****************************************************************
  589. * MISC Helper Tasks
  590. ***************************************************************/
  591. public function updateScores() {
  592. global $init;
  593. require_once (PATH_CORE. '/classes/teamBackend.class.php');
  594. $teamObj = new teamBackend();
  595. $teamObj->updateScores();
  596. redirect(url_for('street_team', 'index'));
  597. }
  598. public function prepareContest() {
  599. global $init;
  600. require_once (PATH_CORE. '/classes/teamBackend.class.php');
  601. $teamObj = new teamBackend();
  602. $teamObj->prepareContest();
  603. redirect(url_for('street_team', 'index'));
  604. }
  605. public function resetContestAdmins() {
  606. global $init;
  607. require_once (PATH_CORE. '/classes/teamBackend.class.php');
  608. $teamObj = new teamBackend();
  609. $teamObj->testResetAdmins();
  610. redirect(url_for('street_team', 'index'));
  611. }
  612. public function cleanupOrphans() {
  613. global $init;
  614. require_once (PATH_CORE. '/classes/teamBackend.class.php');
  615. $teamObj = new teamBackend();
  616. $teamObj->cleanupOrphanedUsers();
  617. redirect(url_for('street_team', 'index'));
  618. }
  619. /****************************************************************
  620. * General Main section
  621. ***************************************************************/
  622. public function index() {
  623. disp_header();
  624. echo "<h1>Index page for Street Team.</h1>";
  625. disp_footer();
  626. }
  627. }
  628. ?>