addticket.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. require __DIR__ . '/../vendor/autoload.php';
  3. # Tanss
  4. include __DIR__ . '/tanss.php';
  5. $tanss = new tanss;
  6. # Settings
  7. setlocale(LC_ALL, 'de_DE', 'de_DE.UTF-8');
  8. error_reporting(E_ALL);
  9. ini_set('display_errors', 0);
  10. # DateTime Settings
  11. date_default_timezone_set('Europe/Berlin');
  12. setlocale(LC_ALL, "de_DE", "de_DE.UTF-8", "de_DE@euro", "deu", "deu_deu", "german");
  13. # Timeouts
  14. ini_set("default_socket_timeout","20");
  15. set_time_limit(20);
  16. stream_context_set_default(array('http' => array('timeout' => 20)));
  17. # We need to use sessions, so you should always start sessions using the below code.
  18. session_start();
  19. # If the user is not logged in redirect to the login page...
  20. // if (!isset($_SESSION['loggedin']) || !$_SESSION['loggedin'] ) { }
  21. // if ( $_SESSION['expire'] == 0 || $_SESSION['expire'] < time() ) {
  22. // # API Requst senden
  23. // $ergebnis = $tanss->login("rmm", "!1nn0cur1ty?");
  24. // if ( $ergebnis==200)
  25. // {
  26. // session_regenerate_id();
  27. // $tanss->writesession($_SESSION);
  28. // $_SESSION['loggedin'] = TRUE;
  29. // } else {
  30. // exit("Incorrect username");
  31. // }
  32. // }
  33. $tanss->readsession($_SESSION);
  34. # Daten aus dem Formular
  35. // $name = trim(stripslashes($_POST['name']));
  36. // $email = trim(stripslashes($_POST['email']));
  37. // $subject = trim(stripslashes($_POST['subject']));
  38. // $computer = strtoupper(trim(stripslashes($_POST['computer'])));
  39. // $phone = trim(stripslashes($_POST['phone']));
  40. // $location = trim(stripslashes($_POST['location']));
  41. // $contact_message = trim(stripslashes($_POST['message']));
  42. // if ($subject == '') { $subject = "Supportanfrage"; }
  43. # Find Device in Tanss
  44. $ergebnis = $tanss->searchDevice($computer, "PCS_ONLY", 162) ;
  45. // echo "<pre>";var_dump($ergebnis);echo "</pre>";
  46. if ( $ergebnis ) { $deviceID = $ergebnis->id; } else { $deviceID=0; }
  47. $message = "Supportanfrage:\n";
  48. $message .= "Vor- / Nachname: " . $name . "\n";
  49. $message .= "Email: " . $email . "\n";
  50. $message .= "Telefon: " . $phone . "\n";
  51. $message .= "Standort: " . $location . "\n";
  52. $message .= "Computer: " . $computer . "\n";
  53. $message .= "Betreff: " . $subject . "\n";
  54. $message .= "Nachricht:\n";
  55. $message .= "--------------";
  56. $message .= "\n";
  57. $message .= $contact_message;
  58. $message .= "\n";
  59. $message .= "--------------";
  60. $message .= "\nDiese Nachricht kam über das Support Formular\n";
  61. # TicketData:
  62. $body = [
  63. # integer: Company id of the ticket. Name is stored in the "linked entities" - "companies". Can only be set if the user has access to the company
  64. "companyId" => 162,
  65. # integer: If the ticket has a remitter, the id goes here. Name is stored in the "linked entities" - "employees"
  66. "remitterId" => 2359,
  67. # string: The title / subject of the ticket
  68. "title" => $subject,
  69. #"title" => "Supportanfrage DEMO",
  70. # string: The content / description of the ticket
  71. "content" => strip_tags($message),
  72. # "content" => "Content / Beschreibung",
  73. # string: External ticket id (optional)
  74. "extTicketId" => "",
  75. # integer: Id of employee which ticket is assigned to. Name is stored in "linked entities" - "employees"
  76. "assignedToEmployeeId" => 0,
  77. # integer: id of department which ticket is assigned to. Name is stored in "linked entities" - "departments"
  78. "assignedToDepartmentId" => 4,
  79. # integer: id of the ticket state. Name is give in "linked entities" - "ticketStates"
  80. "statusId" => 1,
  81. # integer: id of the ticket type. Name is give in "linked entities" - "ticketTypes"
  82. "typeId" => 4,
  83. # integer: if ticket is assigned to device / employee, linktype is given here
  84. "linkTypeId" => 1,
  85. # integer: if ticket is assigned to device / employee, the id of the entity is given here
  86. "linkId" => $deviceID,
  87. # integer <timestamp> : If ticket has a deadline, the date is given here
  88. "deadlineDate" => 0,
  89. # boolean: if ticket is actually a project, this value is true
  90. "project" => false,
  91. # integer: if ticket is a sub-ticket of a project, the id of the project goes here. Name of the project is in the "linked entities" - "tickets"
  92. "projectId" => 0,
  93. # boolean_ if true, this ticket is a "repair ticket"
  94. "repair" => false,
  95. # integer <timestamp>: if ticket has a due date, the timestamp is given here
  96. "dueDate" => 0,
  97. # string Enum: "NO" "YES" "RESUBMISSION" "MAIL" => Determines the "attention" flag state of a ticket
  98. "attention" => "NO",
  99. # integer: gives infos about how the remitter gave the order. Infos are stored in the "linked entities" - "orderBys"
  100. "orderById" => 0,
  101. # string: Enum: "NO" "YES" "NO_PROJECT_INSTALLATION_FEE" => If the ticket has an installation fee, this value is true
  102. "installationFee" => "NO",
  103. # string: Enum: "NONE" "DRIVE_INCLUDED" "DRIVE_EXCLUDED"
  104. # Sets the installation fee drive mode. If it is set to NONE then the system config parameter "leistung.ip.fahrzeit_berechnen" will be used.
  105. # If the company from the ticket has an installation fee drive mode set then that will be used instead of the system config parameter.
  106. "installationFeeDriveMode" => "NONE",
  107. # number <double>: Amount for the installation fee
  108. "installationFeeAmount" => 0,
  109. # boolean: If true, the ticket shall be billed separately
  110. "separateBilling" => false,
  111. # number <double>: if the ticket has a service cap, here the amount is given
  112. "serviceCapAmount" => 0,
  113. # integer: linkTypeId of the relationship (if ticket has a relation)
  114. "relationshipLinkTypeId" => 0,
  115. # integer: linkId of the relationship (if ticket has a relation)
  116. "relationshipLinkId" => 0,
  117. # integer <timestamp>: if the ticket as a resubmission date set, this is given here
  118. "resubmissionDate" => 0,
  119. # integer: Number of estimated minutes which is planned for the ticket
  120. "estimatedMinutes" => 10,
  121. # string: Enum: "NONE" "LOCAL_ADMIN" "TECHNICIAN"
  122. # Determines wether the ticket is assigned to a local ticket admin or not
  123. # NONE: "normal" ticket
  124. # LOCAL_ADMIN: ticket is assigned to a local ticket admin
  125. # TECHNICIAN: local ticket admin has forwarded the ticket to a technician
  126. "localTicketAdminFlag" => "NONE",
  127. # integer: if the ticket is assigned to a local ticket admin, this represents the employee (local ticket admin) who is assigned for this ticket
  128. "localTicketAdminEmployeeId" => 0,
  129. # integer: if the ticket is assignet to a project phase. The name of the phase is stored in the "linked entities" - "phases"
  130. "phaseId" => 0,
  131. # string: If a resubmission text is set, this text is returned here
  132. "resubmissionText" => "",
  133. # string: Sets the order number
  134. "orderNumber" => "",
  135. # integer <timestamp>: If the ticket has a reminder set, the timestamp is returned here
  136. "reminder" => 0,
  137. # string: Enum: "DEFAULT" "DONT_CLEAR_SUPPORTS" "MAY_CLEAR_SUPPORTS"
  138. # describes "how" the supports of a ticket may be cleared. Here, the default value of the OSK may be "overwritten"
  139. "clearanceMode" => "DEFAULT"
  140. ];
  141. $ticket = $tanss->addticket($body);
  142. if ( $ticket->statuscode == 201)
  143. {
  144. echo "Ticket ist mit der id ".$ticket->body->content->id." eingetragen";
  145. // Daten lokal ablegen:
  146. $filename = date("YmdHis") . "_" . $computer . '_api.json';
  147. file_put_contents("../auftraege/".$filename, json_encode($ticket->body, JSON_UNESCAPED_UNICODE), FILE_APPEND | LOCK_EX);
  148. } else {
  149. echo "Fehler beim Anlegen des Tickets via API.";
  150. //echo "<pre>";var_dump($ergebnis);echo "</pre>";
  151. }
  152. ?>