/** *display a user ticket formular and send the ticket to the weclapp account **/ function weclapp_display_ticket_formular($atts) { //extract shortcode parameters extract(shortcode_atts(array('phone_number' => 0, 'additional_recipients' => 0, 'category' => 0), $atts)); //parameters needed for api call $args = array('headers' => array('Authorization' => 'Basic ' . base64_encode("*" . ':' . weclapp_get_option("api_token")))); //display name and email fields $ticketing_content = ' <div id="ticket_name_group" class="form-group"> <label for="wc_ticket_name">' . __("*Name", "weclapp") . '</label> <input id="wc_ticket_name" name="wc_ticket_name" type="text" class="form-control" /> </div> <div id="ticket_email_group" class="form-group"> <label for="wc_ticket_email"> *E-Mail </label> <input id="wc_ticket_email" name="wc_ticket_email" type="text" class="form-control" /> </div>'; //if requested, display additional recipients, phone number and category fields if (true == $additional_recipients) { $ticketing_content .= ' <div id="ticket_additional_email_group" class="form-group"> <label for="wc_ticket_additional_email">' . __("Weitere Empfänger", "weclapp") . '</label> <input id="wc_ticket_additional_email" name="wc_ticket_additional_email" type="text" class="form-control" /> </div>'; } if (true == $phone_number) { $ticketing_content .= ' <div id="ticket_phone_group" class="form-group"> <label for="wc_ticket_phone">' . __("Telefonnummer", "weclapp") . '</label> <input id="wc_ticket_phone" name="wc_ticket_phone" type="text" class="form-control" /> </div>'; } if (true == $category) { //api request to determine the user created categories $ticketCategory = wp_remote_retrieve_body(wp_remote_get('https://' . weclapp_get_option("domain_name") . '.weclapp.com/webapp/api/v1/ticketCategory', $args)); $ticketCategory = json_decode($ticketCategory, true); $ticketCategory = $ticketCategory['result']; $ticketing_content .= ' <div id="ticket_category_group" class="form-group"> <label for="wc_ticket_category">' . __("Kategorie", "weclapp") . '</label> <select id="wc_ticket_category" name="wc_ticket_priority" type="text" value="Test" class="form-control"> <option value="">' . __("Bitte auswählen", "weclapp") . '</option>'; foreach ($ticketCategory as &$val) { $ticketing_content .= ' <option value=' . $val['id'] . '>' . $val['name'] . '</option>'; } $ticketing_content .= ' </select> </div>'; //$ticketing_content .= $result . 'sadadasd'; //error_log($result, 0); } //api request to determine the user created priorities $ticketPriority = wp_remote_retrieve_body(wp_remote_get('https://' . weclapp_get_option("domain_name") . '.weclapp.com/webapp/api/v1/ticketPriority', $args)); $ticketPriority = json_decode($ticketPriority, true); $ticketPriority = $ticketPriority['result']; $ticketing_content .= ' <div id="ticket_priority_group" class="form-group"> <label for="wc_ticket_priority">' . __("*Priorität", "weclapp") . '</label> <select id="wc_ticket_priority" name="wc_ticket_priority" type="text" class="form-control">'; foreach ($ticketPriority as &$val) { $ticketing_content .= ' <option value=' . $val['id'] . '>' . $val['name'] . '</option>'; } //display subject and description field submitbutton calls sendTicket in weclapp.js (AJAX call) $ticketing_content .= ' </select> </div> <div id="ticket_subject_group" class="form-group"> <label for="wc_ticket_subject">' . __("*Betreff", "weclapp") . '</label> <input id="wc_ticket_subject" name="wc_ticket_subject" type="text" class="form-control" /> </div> <div id="ticket_description_group" class="form-group"> <label for="wc_ticket_description">' . __("Beschreibung", "weclapp") . '</label> <textarea id="wc_ticket_description" rows="10" cols ="40" name="wc_ticket_description" class="form-control" /></textarea> </div> <input type="submit" name="submit" id="submitbutton" value="' . __("Senden", "weclapp") . '" onclick="sendTicket( )" />'; $ticketing_content .= '<div style="padding-top: 20px;padding-bottom: 20px;">'; $ticketing_content .= '<div id="ticket_loader" style="display: none;"> <img src="' . plugin_dir_url(__FILE__) . 'assets/icons/ajax-loader.gif"> </div>'; $ticketing_content .= '<div id="ticket_errorbox" class="weclapp-error-message" style="display: none;"><span></span></div>'; $ticketing_content .= '<div id="ticket_successbox" class="weclapp-success-message" style="display: none;"><span></span></div>'; return $ticketing_content; }
function weclapp_create_contact($name, $email, $phone, $api_header, &$data) { //divide name into first name and surname $name = preg_split('/ (?!.* )/', $name); $params = array('body' => json_encode(array("lastName" => $name[1], "firstName" => $name[0], "email" => $email, "partyType" => "PERSON", "company" => "foo", "phone" => $phone)), 'headers' => $api_header); //create the contact in the specified list (contact, lead or customer) $result = wp_remote_post("https://" . weclapp_get_option("domain_name") . ".weclapp.com/webapp/api/v1/" . weclapp_get_option("contact_placement"), $params); $result = weclapp_api_check($result, $data); $partyId = $result['id']; return $partyId; }