PageRenderTime 50ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/php/addtask.php

http://task.codeplex.com
PHP | 69 lines | 44 code | 14 blank | 11 comment | 2 complexity | fe12a1ae1bf7257113bbb54139252807 MD5 | raw file
  1. <?php
  2. require_once "init.php";
  3. use WindowsAzure\Table\Models\Entity;
  4. use WindowsAzure\Table\Models\EdmType;
  5. use WindowsAzure\ServiceBus\Models\BrokeredMessage;
  6. $imageName = (!empty($_FILES['upload']['tmp_name'])) ? gen_uuid() . '.' . pathinfo($_FILES['upload']['name'], PATHINFO_EXTENSION) : '';
  7. $entity = new Entity();
  8. $entity->setPartitionKey('p1');
  9. $entity->setRowKey((string) microtime(true));
  10. $entity->addProperty('Name', EdmType::STRING, $_POST['itemname']);
  11. $entity->addProperty('Category', EdmType::STRING, $_POST['category']);
  12. $entity->addProperty('Date', EdmType::STRING, $_POST['date']);
  13. $entity->addProperty('Complete', EdmType::BOOLEAN, false);
  14. $entity->addProperty('Image', EdmType::STRING, $imageName);
  15. try{
  16. //If we have a file upload it to BLOB storage using the image names
  17. if(!empty($_FILES['upload']['tmp_name'])){
  18. $blobRestProxy->createBlockBlob('images', $imageName, fopen($_FILES['upload']['tmp_name'],"r"));
  19. }
  20. $tableRestProxy->insertEntity('tasks', $entity);
  21. // Create message.
  22. if ($sbEnable)
  23. {
  24. $message = new BrokeredMessage();
  25. $message->setProperty('action','add');
  26. $message->setProperty('sample','php');
  27. $message->setBody($_POST['itemname']);
  28. // Send message.
  29. $serviceBusRestProxy->sendTopicMessage("tasks", $message);
  30. }
  31. }
  32. catch(ServiceException $e){
  33. $code = $e->getCode();
  34. $error_message = $e->getMessage();
  35. echo $code.": ".$error_message."<br />";
  36. }
  37. header('Location: index.php');
  38. function gen_uuid() {
  39. return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
  40. // 32 bits for "time_low"
  41. mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
  42. // 16 bits for "time_mid"
  43. mt_rand( 0, 0xffff ),
  44. // 16 bits for "time_hi_and_version",
  45. // four most significant bits holds version number 4
  46. mt_rand( 0, 0x0fff ) | 0x4000,
  47. // 16 bits, 8 bits for "clk_seq_hi_res",
  48. // 8 bits for "clk_seq_low",
  49. // two most significant bits holds zero and one for variant DCE1.1
  50. mt_rand( 0, 0x3fff ) | 0x8000,
  51. // 48 bits for "node"
  52. mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
  53. );
  54. }
  55. ?>