function inline_edit_mg_task_meta() { $response = false; $new_data = ''; $r = array(); // we need the post IDs $post_id = isset($_POST['post_ID']) && !empty($_POST['post_ID']) ? $_POST['post_ID'] : NULL; // if we have post IDs if (!empty($post_id) && is_numeric($post_id)) { if (!empty($_POST['referrer']) && $_POST['referrer'] !== 'quick_save') { $_SESSION['doing_inline_edit'] = true; $field = str_replace('-', '_', $_POST['referrer']); $_SESSION['changed_docs'] = array('invoices' => array(), 'estimates' => array()); if ($field === 'status') { $field = 'task_status'; } // if it has a value, doesn't update if empty on bulk if (isset($_POST[$field]) && !empty($_POST[$field])) { if ($field === 'task_status') { $update_post = wp_update_post(array('ID' => $post_id, 'post_status' => $_POST[$field])); if (is_numeric($update_post) && intval($update_post) > 0) { $new_data = $_POST[$field]; } else { $new_data = false; } } else { $old_value = get_post_meta($post_id, $field, true); $response = update_post_meta($post_id, $field, $_POST[$field], $old_value); $new_data = get_post_meta($post_id, $field, true); if ($field === 'estimated_time' && $response === true) { if (isset($_SESSION['changed_docs']['invoices']) && check_for_value($_SESSION['changed_docs']['invoices'])) { foreach ($_SESSION['changed_docs']['invoices'] as $item) { $item_id = maybe_get_pod_id($item); $object = SI_Invoice::get_instance($item_id[0]); if (isset($object) && is_object($object)) { $object->set_calculated_total(); } } } if (isset($_SESSION['changed_docs']['estimates']) && check_for_value($_SESSION['changed_docs']['estimates'])) { foreach ($_SESSION['changed_docs']['estimates'] as $item) { $item_id = maybe_get_pod_id($item); $object = SI_Estimate::get_instance($item_id[0]); if (isset($object) && is_object($object)) { $object->set_calculated_total(); } } } if (!is_numeric($new_data)) { $new_data = convert_estimated_time_to_minutes($new_data); } } } $r = array('post_id' => (int) $post_id, $field => $new_data); } } elseif ($_POST['referrer'] == 'quick_save') { $new_data = get_post_meta($post_id, 'estimated_time', true); $r = array('post_id' => (int) $post_id, 'estimated_time' => (int) $new_data); } unset($_SESSION['changed_docs']); } unset($_SESSION['doing_inline_edit']); $response = json_encode($r, JSON_FORCE_OBJECT); exit($response); }
$email = clean_text($_REQUEST["email"]); // save op session request $reqs = array(); // run the requests - need one for each priority that is given on page $reqs = check_for_value($values, "1", $reqs); $reqs = check_for_value($values, "2", $reqs); $reqs = check_for_value($values, "3", $reqs); $reqs = check_for_value($values, "4", $reqs); $reqs = check_for_value($values, "5", $reqs); $reqs = check_for_value($values, "6", $reqs); $reqs = check_for_value($values, "7", $reqs); $reqs = check_for_value($values, "8", $reqs); $reqs = check_for_value($values, "9", $reqs); $reqs = check_for_value($values, "10", $reqs); $reqs = check_for_value($values, "11", $reqs); $reqs = check_for_value($values, "12", $reqs); // so reqs now is an ordered list of requests // do an insert of the request $op = "REPLACE INTO " . $event_tools_db_prefix . "eventtools_opsession_req (`opsreq_person_email`, `opsreq_pri1`, `opsreq_pri2`, `opsreq_pri3`, `opsreq_pri4`, `opsreq_pri5`, `opsreq_pri6`, `opsreq_pri7`, `opsreq_pri8`, `opsreq_pri9`, `opsreq_pri10`, `opsreq_pri11`, `opsreq_pri12`, `opsreq_comment`) VALUES " . "('" . $email . "','" . $reqs[0] . "','" . $reqs[1] . "','" . $reqs[2] . "','" . $reqs[3] . "','" . $reqs[4] . "','" . $reqs[5] . "','" . $reqs[6] . "','" . $reqs[7] . "','" . $reqs[8] . "','" . $reqs[9] . "','" . $reqs[10] . "','" . $reqs[11] . "','" . clean_text($_REQUEST["comments"]) . "');"; //print 'Request [ '.$op.' ] <p>'; mysql_query($op); // see if the user already exists $findu = "SELECT customers_id FROM " . $event_tools_db_prefix . "customers WHERE customers_email_address = '" . $email . "';"; $reqs = mysql_query($findu); if (mysql_num_rows($reqs) == 0) { // no, do an insert of the user $user = "******" . $event_tools_db_prefix . "customers (`customers_email_address`, `customers_firstname`, `customers_lastname`, `customers_telephone`, `customers_cellphone`, `customers_create_date`, `customers_x2011_emerg_contact_name`, `customers_x2011_emerg_contact_phone`) VALUES " . "('" . $email . "','" . clean_text($_REQUEST["fname"]) . "','" . clean_text($_REQUEST["lname"]) . "','" . clean_text($_REQUEST["phone"]) . "','" . clean_text($_REQUEST["cell"]) . "',now(),'" . clean_text($_REQUEST["econtact"]) . "','" . clean_text($_REQUEST["ephone"]) . "');"; //print 'Insert of user: [ '.$user.' ] '; mysql_query($user); if (mysql_errno() != 0) { print "<p>Error in INSERT customers: " . mysql_errno() . ": " . mysql_error() . "</p>";
function invoice_or_estimate_update($est_to_add, $est_to_remove, $inv_to_add, $inv_to_remove, $changed_fields, $id) { if (isset($changed_fields['add_line_item_to_estimate'])) { if ($changed_fields['add_line_item_to_estimate'] === '' || isset($_SESSION['prev_est']) && check_for_value($_SESSION['prev_est']) === true) { if (isset($_SESSION['prev_est']) && check_for_value($_SESSION['prev_est']) === true) { $current_estimates = maybe_get_pod_id($_SESSION['prev_est']); if ($est_to_remove === false) { if (check_for_value($changed_fields['add_line_item_to_estimate']) === false) { $est_to_remove = false; } else { if (!is_array($current_estimates)) { $current_estimates = explode(",", $current_estimates); } if (!is_array($changed_fields['add_line_item_to_estimate'])) { $changed_fields['add_line_item_to_estimate'] = explode(",", $changed_fields['add_line_item_to_estimate']); } $est_to_remove = array_diff($current_estimates, $changed_fields['add_line_item_to_estimate']); } } } } if (is_array($changed_fields['add_line_item_to_estimate']) && check_for_value($changed_fields['add_line_item_to_estimate']) === true && (!isset($est_to_add) || isset($est_to_add) && check_for_value($est_to_add) === false)) { $est_to_add = $changed_fields['add_line_item_to_estimate']; } } if (isset($changed_fields['add_line_item_to_invoice'])) { if ($changed_fields['add_line_item_to_invoice'] === '' || isset($_SESSION['prev_inv']) && check_for_value($_SESSION['prev_inv']) === true) { if (isset($_SESSION['prev_inv']) && check_for_value($_SESSION['prev_inv']) === true) { $current_invoices = maybe_get_pod_id($_SESSION['prev_inv']); if ($inv_to_remove === false) { if (check_for_value($changed_fields['add_line_item_to_invoice']) === false) { $inv_to_remove = false; } else { if (!is_array($current_invoices)) { $current_invoices = explode(",", $current_invoices); } if (!is_array($changed_fields['add_line_item_to_invoice'])) { $changed_fields['add_line_item_to_invoice'] = explode(",", $changed_fields['add_line_item_to_invoice']); } $inv_to_remove = array_diff($current_invoices, $changed_fields['add_line_item_to_invoice']); } } } } if (is_array($changed_fields['add_line_item_to_invoice']) && check_for_value($changed_fields['add_line_item_to_invoice']) === true && (!isset($inv_to_add) || isset($inv_to_add) && check_for_value($inv_to_add) === false)) { $inv_to_add = $changed_fields['add_line_item_to_invoice']; } } $invoice_changes = array(); $estimate_changes = array(); if ($inv_to_add !== false) { $invoice_add = array('invoices_to_add' => $inv_to_add); $invoice_changes = array_merge($invoice_changes, $invoice_add); } if ($inv_to_remove !== false) { $inv_remove = array('invoices_to_remove' => $inv_to_remove); $invoice_changes = array_merge($invoice_changes, $inv_remove); } if ($est_to_add !== false) { $est_add = array('estimates_to_add' => $est_to_add); $estimate_changes = array_merge($estimate_changes, $est_add); } if ($est_to_remove !== false) { $est_remove = array('estimates_to_remove' => $est_to_remove); $estimate_changes = array_merge($estimate_changes, $est_remove); } if (isset($changed_fields['percent_adjustment']) || isset($changed_fields['rate']) || isset($changed_fields['quantity']) || isset($changed_fields['estimated_time'])) { if (isset($inv_to_add) && $inv_to_add !== false && !empty($inv_to_add) && !is_null($inv_to_add) && (isset($inv_to_add[0]) && $inv_to_add[0] !== false && !empty($inv_to_add[0]) && !is_null($inv_to_add[0])) || isset($_SESSION["update_inv"]) && $_SESSION["update_inv"] !== false && !empty($_SESSION["update_inv"]) && !is_null($_SESSION["update_inv"]) && (isset($_SESSION["update_inv"][0]) && $_SESSION["update_inv"][0] !== false && !empty($_SESSION["update_inv"][0]) && !is_null($_SESSION["update_inv"][0])) || isset($_SESSION["prev_inv"]) && $_SESSION["prev_inv"] !== false && !empty($_SESSION["prev_inv"]) && !is_null($_SESSION["prev_inv"]) && (isset($_SESSION["prev_inv"][0]) && $_SESSION["prev_inv"][0] !== false && !empty($_SESSION["prev_inv"][0]) && !is_null($_SESSION["prev_inv"][0]))) { if (isset($_SESSION["update_inv"]) && $_SESSION["update_inv"] !== false && !empty($_SESSION["update_inv"]) && !is_null($_SESSION["update_inv"]) && (isset($_SESSION["update_inv"][0]) && $_SESSION["update_inv"][0] !== false && !empty($_SESSION["update_inv"][0]) && !is_null($_SESSION["update_inv"][0]))) { $inv_to_add = maybe_get_pod_id($_SESSION["update_inv"]); } elseif (isset($_SESSION["prev_inv"]) && $_SESSION["prev_inv"] !== false && !empty($_SESSION["prev_inv"]) && !is_null($_SESSION["prev_inv"]) && (isset($_SESSION["prev_inv"][0]) && $_SESSION["prev_inv"][0] !== false && !empty($_SESSION["prev_inv"][0]) && !is_null($_SESSION["prev_inv"][0]))) { $inv_to_add = maybe_get_pod_id($_SESSION["prev_inv"]); } $inv_update = array('invoices_to_update' => $inv_to_add); $invoice_changes = array_merge($invoice_changes, $inv_update); } } if (isset($changed_fields['percent_adjustment']) || isset($changed_fields['rate']) || isset($changed_fields['quantity']) || isset($changed_fields['estimated_time'])) { if (isset($est_to_add) && $est_to_add !== false && !empty($est_to_add) && !is_null($est_to_add) && (isset($est_to_add[0]) && $est_to_add[0] !== false && !empty($est_to_add[0]) && !is_null($est_to_add[0])) || isset($_SESSION["update_est"]) && $_SESSION["update_est"] !== false && !empty($_SESSION["update_est"]) && !is_null($_SESSION["update_est"]) && (isset($_SESSION["update_est"][0]) && $_SESSION["update_est"][0] !== false && !empty($_SESSION["update_est"][0]) && !is_null($_SESSION["update_est"][0])) || isset($_SESSION["prev_est"]) && $_SESSION["prev_est"] !== false && !empty($_SESSION["prev_est"]) && !is_null($_SESSION["prev_est"]) && (isset($_SESSION["prev_est"][0]) && $_SESSION["prev_est"][0] !== false && !empty($_SESSION["prev_est"][0]) && !is_null($_SESSION["prev_est"][0]))) { if (isset($_SESSION["update_est"]) && $_SESSION["update_est"] !== false && !empty($_SESSION["update_est"]) && !is_null($_SESSION["update_est"]) && (isset($_SESSION["update_est"][0]) && $_SESSION["update_est"][0] !== false && !empty($_SESSION["update_est"][0]) && !is_null($_SESSION["update_est"][0]))) { $est_to_add = maybe_get_pod_id($_SESSION["update_est"]); } elseif (isset($_SESSION["prev_est"]) && $_SESSION["prev_est"] !== false && !empty($_SESSION["prev_est"]) && !is_null($_SESSION["prev_est"]) && (isset($_SESSION["prev_est"][0]) && $_SESSION["prev_est"][0] !== false && !empty($_SESSION["prev_est"][0]) && !is_null($_SESSION["prev_est"][0]))) { $est_to_add = maybe_get_pod_id($_SESSION["prev_est"]); } $est_update = array('estimates_to_update' => $est_to_add); $estimate_changes = array_merge($estimate_changes, $est_update); } } $output = ['estimates' => $estimate_changes, 'invoices' => $invoice_changes]; return $output; }