/quest/php/updateActivity.php

https://github.com/qarnac/CyberHawk-Adventure · PHP · 56 lines · 50 code · 4 blank · 2 comment · 6 complexity · 252d6b08f1e2bc3e02f7adf43d9ce8f1 MD5 · raw file

  1. <?php
  2. include '../php/credentials.php';
  3. include '../php/getConstants.php';
  4. $content=$_POST['contents'];
  5. $content=json_decode($content);
  6. // If the optional questions are answered, store the answers into an array and JSON encode the array to store into the database.
  7. $answera=(isset($content->optionalAnswer1))? $content->optionalAnswer1:"";
  8. $answerb=(isset($content->optionalAnswer2))? $content->optionalAnswer2:"";
  9. $answerc=(isset($content->optionalAnswer3))? $content->optionalAnswer3:"";
  10. $additionalAnswers=array("answera"=>$answera, "answerb"=>$answerb, "answerc"=>$answerc);
  11. $additionalAnswers=json_encode($additionalAnswers);
  12. mysql_query("UPDATE stud_activity" .
  13. " SET partner_names=" .'"'. mysql_escape_string($content->partner_names) .'"' .
  14. ", additionalAnswers=" .'"' . mysql_escape_string($additionalAnswers) .'"' .
  15. " , choices=" . '"' . mysql_escape_string(choic($content)) .'"' .
  16. " , status=" . '"' . mysql_escape_string($content->status) . '"' .
  17. " , mquestion=" . '"' . mysql_escape_string($content->mquestion) . '"' .
  18. ", interesting_url=" . '"' . mysql_escape_string($content->interesting_url) . '"' .
  19. " WHERE `id` = " . mysql_escape_string($content->id) . ";") or die(mysql_error());
  20. echo "true";
  21. //decodes the image to a binary file and finally a jpeg file
  22. function writeImage($imageData,$outputfile)
  23. {
  24. $fp = fopen($outputfile, 'wb');
  25. $imageData=str_replace(' ','+',$imageData);
  26. fwrite($fp, base64_decode($imageData));
  27. fclose($fp);
  28. }
  29. function choic($data)
  30. {
  31. $choic=array("choices"=>array());
  32. if($data->a!="")
  33. array_push($choic['choices'],array('choice'=>'a','content'=>$data->a,'ans'=> btos($data->answer=='a')));
  34. if($data->b!="")
  35. array_push($choic['choices'],array('choice'=>'b','content'=>$data->b,'ans'=> btos($data->answer=='b')));
  36. if($data->c!="")
  37. array_push($choic['choices'],array('choice'=>'c','content'=>$data->c,'ans'=> btos($data->answer=='c')));
  38. if($data->d!="")
  39. array_push($choic['choices'],array('choice'=>'d','content'=>$data->d,'ans'=> btos($data->answer=='d')));
  40. if($data->e!="")
  41. array_push($choic['choices'],array('choice'=>'e','content'=>$data->e,'ans'=> btos($data->answer=='e')));
  42. $choic=json_encode($choic);
  43. return $choic;
  44. }
  45. function btos($x)
  46. {
  47. if($x)
  48. return "true";
  49. else
  50. return "false";
  51. }
  52. ?>