/** * @param $invoice_id * @param $invoice_data * @return array * * todo: make this method call the other 'get_replace_fields' available in website/job/etc.. */ public static function get_replace_fields($invoice_id, $invoice_data = false) { if (!$invoice_data) { $invoice_data = self::get_invoice($invoice_id); } $customer_data = array(); if ($invoice_data['customer_id']) { $customer_data = module_customer::get_replace_fields($invoice_data['customer_id'], $invoice_data['user_id']); } if (!is_array($customer_data)) { $customer_data = array(); } $data = array_merge($customer_data, $invoice_data); // so we get total_amount_due and stuff. $data = array_merge($data, array('invoice_number' => htmlspecialchars($invoice_data['name']), 'project_type' => _l(module_config::c('project_name_single', 'Website')), 'print_link' => self::link_public_print($invoice_id), 'title' => module_config::s('admin_system_name'), 'invoice_paid' => $invoice_data['total_amount_due'] <= 0 ? '<p> <font style="font-size: 1.6em;"><strong>' . _l('INVOICE PAID') . '</strong></font> </p>' : '', 'is_invoice_paid' => $invoice_data['total_amount_due'] <= 0 ? 1 : '', 'date_create' => print_date($invoice_data['date_create']), 'due_date' => print_date($invoice_data['date_due']))); $data['total_amount'] = dollar($invoice_data['total_amount'], true, $invoice_data['currency_id']); $data['total_amount_due'] = dollar($invoice_data['total_amount_due'], true, $invoice_data['currency_id']); $data['total_amount_paid'] = dollar($invoice_data['total_amount_paid'], true, $invoice_data['currency_id']); $data['date_paid'] = print_date($invoice_data['date_paid']); $data['date_due'] = print_date($invoice_data['date_due']); $data['date_sent'] = print_date($invoice_data['date_sent']); $data['invoice_number'] = $invoice_data['name']; $data['invoice_url'] = module_invoice::link_public($invoice_id); $data['invoice_date_range'] = ''; if ($invoice_data['date_renew'] != '0000-00-00') { $data['invoice_date_range'] = _l('%s to %s', print_date($invoice_data['date_create']), print_date(strtotime("-1 day", strtotime($invoice_data['date_renew'])))); } if (isset($invoice_data['credit_note_id']) && $invoice_data['credit_note_id']) { $credit_invoice = module_invoice::get_invoice($invoice_data['credit_note_id'], true); $data['credit_invoice_number'] = htmlspecialchars($credit_invoice['name']); } $data['invoice_notes'] = ''; // grab any public notes if (class_exists('module_note', false) && module_note::is_plugin_enabled()) { $notes = module_note::get_notes(array('public' => 1, 'owner_table' => 'invoice', 'owner_id' => $invoice_id)); if (count($notes) > 1) { $data['invoice_notes'] .= '<ul>'; foreach ($notes as $note) { if ($note['public']) { $data['invoice_notes'] .= '<li>'; $data['invoice_notes'] .= htmlspecialchars($note['note']); $data['invoice_notes'] .= '</li>'; } } $data['invoice_notes'] .= '</ul>'; } else { $note = array_shift($notes); $data['invoice_notes'] .= htmlspecialchars($note['note']); } } $job_names = $website_url = $project_names = $project_names_and_url = array(); foreach ($invoice_data['job_ids'] as $job_id) { $job_data = module_job::get_job($job_id); if ($job_data && $job_data['job_id'] == $job_id) { $job_names[$job_data['job_id']] = $job_data['name']; if (module_config::c('job_invoice_show_date_range', 1)) { // check if this job is a renewable job. if ($job_data['date_renew'] != '0000-00-00') { $data['invoice_date_range'] = _l('%s to %s', print_date($job_data['date_start']), print_date(strtotime("-1 day", strtotime($job_data['date_renew'])))); } } $fields = module_job::get_replace_fields($job_id, $job_data); foreach ($fields as $key => $val) { if (!isset($data[$key]) || !$data[$key] && $val) { $data[$key] = $val; } } if ($job_data['website_id']) { $website_data = module_website::get_website($job_data['website_id']); if ($website_data && $website_data['website_id'] == $job_data['website_id']) { if (isset($website_data['url']) && $website_data['url']) { $website_url[$website_data['website_id']] = module_website::urlify($website_data['url']); $website_data['name_url'] = $website_data['name'] . ' (' . module_website::urlify($website_data['url']) . ')'; } else { $website_data['name_url'] = $website_data['name']; } $project_names[$website_data['website_id']] = $website_data['name']; $project_names_and_url[$website_data['website_id']] = $website_data['name_url']; $fields = module_website::get_replace_fields($website_data['website_id'], $website_data); foreach ($fields as $key => $val) { if (!isset($data[$key]) || !$data[$key] && $val) { $data[$key] = $val; } } } } } } if (isset($invoice_data['website_id']) && $invoice_data['website_id']) { $website_data = module_website::get_website($invoice_data['website_id']); if ($website_data && $website_data['website_id'] == $invoice_data['website_id']) { if (isset($website_data['url']) && $website_data['url']) { $website_url[$website_data['website_id']] = module_website::urlify($website_data['url']); $website_data['name_url'] = $website_data['name'] . ' (' . module_website::urlify($website_data['url']) . ')'; } else { $website_data['name_url'] = $website_data['name']; } $project_names[$website_data['website_id']] = $website_data['name']; $project_names_and_url[$website_data['website_id']] = $website_data['name_url']; $fields = module_website::get_replace_fields($website_data['website_id'], $website_data); foreach ($fields as $key => $val) { if (!isset($data[$key]) || !$data[$key] && $val) { $data[$key] = $val; } } } } $data['website_name'] = $data['project_name'] = forum_text(count($project_names) ? implode(', ', $project_names) : ''); $data['website_name_url'] = forum_text(count($project_names_and_url) ? implode(', ', $project_names_and_url) : ''); $data['website_url'] = forum_text(count($website_url) ? implode(', ', $website_url) : ''); $data['job_name'] = forum_text($job_names ? implode(', ', $job_names) : ''); if (class_exists('module_group', false)) { // get the job groups $wg = array(); $g = array(); foreach ($invoice_data['job_ids'] as $group_job_id) { $group_job_id = (int) trim($group_job_id); if ($group_job_id > 0) { $job_data = module_job::get_job($group_job_id); foreach (module_group::get_groups_search(array('owner_table' => 'job', 'owner_id' => $group_job_id)) as $group) { $g[$group['group_id']] = $group['name']; } // get the website groups if ($job_data['website_id']) { foreach (module_group::get_groups_search(array('owner_table' => 'website', 'owner_id' => $job_data['website_id'])) as $group) { $wg[$group['group_id']] = $group['name']; } } } } if (isset($invoice_data['website_id']) && $invoice_data['website_id']) { foreach (module_group::get_groups_search(array('owner_table' => 'website', 'owner_id' => $invoice_data['website_id'])) as $group) { $wg[$group['group_id']] = $group['name']; } } $data['job_group'] = implode(', ', $g); $data['website_group'] = implode(', ', $wg); } // addition. find all extra keys for this invoice and add them in. // we also have to find any EMPTY extra fields, and add those in as well. if (class_exists('module_extra', false) && module_extra::is_plugin_enabled()) { $all_extra_fields = module_extra::get_defaults('invoice'); foreach ($all_extra_fields as $e) { $data[$e['key']] = _l('N/A'); } // and find the ones with values: $extras = module_extra::get_extras(array('owner_table' => 'invoice', 'owner_id' => $invoice_id)); foreach ($extras as $e) { $data[$e['extra_key']] = $e['extra']; } } $new_data = hook_handle_callback('invoice_replace_fields', $invoice_id, $data); if (is_array($new_data)) { foreach ($new_data as $new_d) { $data = array_merge($data, $new_d); } } return $data; }
echo $website_id; ?> " /> <?php $fields = array('fields' => array('name' => 'Name')); module_form::set_required($fields); module_form::prevent_exit(array('valid_exits' => array('.submit_button', '.form_save'))); hook_handle_callback('layout_column_half', 1, '35'); $fieldset_data = array('heading' => array('type' => 'h3', 'title' => _l(module_config::c('project_name_single', 'Website') . ' Details')), 'class' => 'tableclass tableclass_form tableclass_full', 'elements' => array('name' => array('title' => _l('Name'), 'field' => array('type' => 'text', 'name' => 'name', 'value' => $website['name']))), 'extra_settings' => array('owner_table' => 'website', 'owner_key' => 'website_id', 'owner_id' => $website['website_id'], 'layout' => 'table_row', 'allow_new' => module_website::can_i('create', 'Websites'), 'allow_edit' => module_website::can_i('create', 'Websites'))); if (module_config::c('project_display_url', 1)) { if (!isset($website['url']) || !strlen($website['url'])) { $website['url'] = module_config::c('project_default_url', 'http://'); } $fieldset_data['elements']['url'] = array('title' => _l('URL'), 'fields' => array(array('type' => 'text', 'name' => 'url', 'value' => $website['url'], 'style' => 'width:200px;'), $website['url'] ? ' <a href="' . module_website::urlify($website['url']) . '" target="_blank">' . _l('open »') . '</a>' : '')); } $fieldset_data['elements']['Status'] = array('title' => _l('Status'), 'fields' => array(array('type' => 'select', 'name' => 'status', 'value' => $website['status'], 'options' => module_website::get_statuses(), 'allow_new' => true))); echo module_form::generate_fieldset($fieldset_data); /*** ADVANCED ****/ if (module_website::can_i('edit', 'Websites')) { $c = array(); $res = module_customer::get_customers(); foreach ($res as $row) { $c[$row['customer_id']] = $row['customer_name']; } $fieldset_data = array('heading' => array('type' => 'h3', 'title' => _l('Advanced')), 'class' => 'tableclass tableclass_form tableclass_full', 'elements' => array()); if (count($res) <= 1 && $website['customer_id'] && isset($c[$website['customer_id']])) { $fieldset_data['elements']['change'] = array('title' => _l('Change Customer'), 'fields' => array(htmlspecialchars($c[$website['customer_id']]), array('type' => 'hidden', 'name' => 'customer_id', 'value' => $website['customer_id']))); } else { $fieldset_data['elements']['change'] = array('title' => _l('Change Customer'), 'fields' => array(array('type' => 'select', 'name' => 'customer_id', 'options' => $c, 'value' => $website['customer_id'], 'help' => 'Changing a customer will also change all the current linked jobs and invoices across to this new customer.')));
public static function hook_invoice_replace_fields($callback_name, $invoice_id, $existing_data) { $new_data = array(); $new_data['subscription_name'] = ''; if ((int) $invoice_id > 0) { // check if this invoice is linked to any subscription payments. $subscription_history = get_single('subscription_history', 'invoice_id', $invoice_id); if ($subscription_history) { //$subscription_member_history = self::get_subscription_history($subscription_history['subscription_id'], $subscription_history['member_id'], $subscription_history['customer_id']); $subscription_owner = get_single('subscription_owner', 'subscription_owner_id', $subscription_history['subscription_owner_id']); $subscriptions = module_subscription::get_subscriptions_by($subscription_owner['owner_table'], $subscription_owner['owner_id']); /*if(isset($subscription_history['member_id']) && $subscription_history['member_id']){ $subscriptions = module_subscription::get_subscriptions_by_member($subscription_history['member_id']); }else if(isset($subscription_history['customer_id']) && $subscription_history['customer_id']){ $subscriptions = module_subscription::get_subscriptions_by_customer($subscription_history['customer_id']); }*/ if (isset($subscriptions[$subscription_history['subscription_id']])) { $subscription = self::get_subscription($subscription_history['subscription_id']); $invoice_data = module_invoice::get_invoice($invoice_id, true); $new_data['subscription_name'] = $subscription['name']; // it might not be 'date_create' it might be days in the future if (isset($subscription_history['from_next_due_date']) && $subscription_history['from_next_due_date'] && $subscription_history['from_next_due_date'] != '0000-00-00') { $new_data['invoice_date_range'] = self::_calculate_next_time(strtotime($subscription_history['from_next_due_date']), $subscription, true); } else { $new_data['invoice_date_range'] = self::_calculate_next_time(strtotime($invoice_data['date_create']), $subscription, true); } // is this linked to a website? pull in website data into the invoice replace fields (code copied from invoice.php) if ($subscription_owner['owner_table'] == 'website') { $website_data = module_website::get_website($subscription_owner['owner_id']); if ($website_data && $website_data['website_id'] == $subscription_owner['owner_id']) { $website_url = $project_names = $project_names_and_url = array(); if (isset($website_data['url']) && $website_data['url']) { $website_url[$website_data['website_id']] = module_website::urlify($website_data['url']); $website_data['name_url'] = $website_data['name'] . ' (' . module_website::urlify($website_data['url']) . ')'; } else { $website_data['name_url'] = $website_data['name']; } $project_names[$website_data['website_id']] = $website_data['name']; $project_names_and_url[$website_data['website_id']] = $website_data['name_url']; if (!$existing_data['website_name']) { $new_data['website_name'] = $new_data['project_name'] = forum_text(count($project_names) ? implode(', ', $project_names) : ''); } if (!$existing_data['website_name_url']) { $new_data['website_name_url'] = forum_text(count($project_names_and_url) ? implode(', ', $project_names_and_url) : ''); } if (!$existing_data['website_url']) { $new_data['website_url'] = forum_text(count($website_url) ? implode(', ', $website_url) : ''); } } } } } } return $new_data; }
public static function get_replace_fields($quote_id, $quote_data = false) { if (!$quote_data) { $quote_data = self::get_quote($quote_id); } $data = array('quote_number' => htmlspecialchars($quote_data['name']), 'quote_name' => htmlspecialchars($quote_data['name']), 'project_type' => _l(module_config::c('project_name_single', 'Website')), 'print_link' => self::link_public_print($quote_id), 'quote_url' => self::link_public($quote_id), 'title' => module_config::s('admin_system_name'), 'create_date' => print_date($quote_data['date_create'])); if (isset($quote_data['customer_id']) && $quote_data['customer_id']) { $customer_data = module_customer::get_replace_fields($quote_data['customer_id'], $quote_data['contact_user_id'] ? $quote_data['contact_user_id'] : false); $data = array_merge($data, $customer_data); // so we get total_amount_due and stuff. } $user_details = array('staff_first_name' => '', 'staff_last_name' => '', 'staff_email' => '', 'staff_phone' => '', 'staff_fax' => '', 'staff_mobile' => ''); if (isset($quote_data['user_id']) && $quote_data['user_id']) { $user_data = module_user::get_user($quote_data['user_id'], false); if ($user_data && $user_data['user_id'] == $quote_data['user_id']) { $user_details = array('staff_first_name' => $user_data['name'], 'staff_last_name' => $user_data['last_name'], 'staff_email' => $user_data['email'], 'staff_phone' => $user_data['phone'], 'staff_fax' => $user_data['fax'], 'staff_mobile' => $user_data['mobile']); } } $data = array_merge($data, $user_details); foreach ($quote_data as $key => $val) { if (strpos($key, 'date') !== false) { $quote_data[$key] = print_date($val); } } if (isset($quote_data['description'])) { $quote_data['description'] = module_security::purify_html($quote_data['description']); } // $customer_data = $quote_data['customer_id'] ? module_customer::get_replace_fields($quote_data['customer_id']) : array(); // $website_data = $quote_data['website_id'] ? module_website::get_replace_fields($quote_data['website_id']) : array(); // $data = array_merge($data,$customer_data,$website_data,$quote_data); $data = array_merge($data, $quote_data); $website_url = $project_names = $project_names_and_url = array(); if ($quote_data['website_id']) { $website_data = module_website::get_website($quote_data['website_id']); if ($website_data && $website_data['website_id'] == $quote_data['website_id']) { if (isset($website_data['url']) && $website_data['url']) { $website_url[$website_data['website_id']] = module_website::urlify($website_data['url']); $website_data['name_url'] = $website_data['name'] . ' (' . module_website::urlify($website_data['url']) . ')'; } else { $website_data['name_url'] = $website_data['name']; } $project_names[$website_data['website_id']] = $website_data['name']; $project_names_and_url[$website_data['website_id']] = $website_data['name_url']; $fields = module_website::get_replace_fields($website_data['website_id'], $website_data); foreach ($fields as $key => $val) { if (!isset($data[$key]) || !$data[$key] && $val) { $data[$key] = $val; } } } } $data['website_name'] = $data['project_name'] = forum_text(count($project_names) ? implode(', ', $project_names) : ''); $data['website_name_url'] = forum_text(count($project_names_and_url) ? implode(', ', $project_names_and_url) : ''); $data['website_url'] = forum_text(count($website_url) ? implode(', ', $website_url) : ''); if (class_exists('module_group', false) && module_group::is_plugin_enabled()) { // get the quote groups $wg = array(); $g = array(); if ($quote_id > 0) { $quote_data = module_quote::get_quote($quote_id); foreach (module_group::get_groups_search(array('owner_table' => 'quote', 'owner_id' => $quote_id)) as $group) { $g[$group['group_id']] = $group['name']; } /*// get the website groups foreach(module_group::get_groups_search(array( 'owner_table' => 'website', 'owner_id' => $quote_data['website_id'], )) as $group){ $wg[$group['group_id']] = $group['name']; }*/ } $data['quote_group'] = implode(', ', $g); /*$data['website_group'] = implode(', ',$wg);*/ } // addition. find all extra keys for this quote and add them in. // we also have to find any EMPTY extra fields, and add those in as well. if (class_exists('module_extra', false) && module_extra::is_plugin_enabled()) { $all_extra_fields = module_extra::get_defaults('quote'); foreach ($all_extra_fields as $e) { $data[$e['key']] = _l('N/A'); } // and find the ones with values: $extras = module_extra::get_extras(array('owner_table' => 'quote', 'owner_id' => $quote_id)); foreach ($extras as $e) { $data[$e['extra_key']] = $e['extra']; } } // also do this for customer fields /*if($quote_data['customer_id']){ $all_extra_fields = module_extra::get_defaults('customer'); foreach($all_extra_fields as $e){ $data[$e['key']] = _l('N/A'); } $extras = module_extra::get_extras(array('owner_table'=>'customer','owner_id'=>$quote_data['customer_id'])); foreach($extras as $e){ $data[$e['extra_key']] = $e['extra']; } }*/ return $data; }
public function external_hook($hook) { switch ($hook) { case 'popup': // popup not used any more. cross domain issues. // load up the full script to be injected into our clients website. $website_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false; $change_request_id = $change_id = isset($_REQUEST['change_id']) ? (int) $_REQUEST['change_id'] : false; $hash = isset($_REQUEST['hash']) ? $_REQUEST['hash'] : false; $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : false; if ($type == 'popupjs') { @ob_end_clean(); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Cache-Control: no-cache"); header("Pragma: no-cache"); header("Content-type: text/javascript"); } if ($website_id && $hash && module_change_request::link_popup($website_id, true) == $hash) { $change_history = module_change_request::get_remaining_changes($website_id); $step = isset($_REQUEST['step']) ? (int) $_REQUEST['step'] : 0; // get the change details out if ($change_request_id) { $change_request = module_change_request::get_change_request_by_website($website_id, $change_request_id); } else { $change_request = array(); } if (!$change_request) { $change_request = array('change_request_id' => 0, 'name' => '', 'request' => '', 'attachments' => array()); } switch ($type) { case 'save': // saving a change. $data = $_POST; $data['url'] = urldecode($data['url']); $data['website_id'] = $website_id; $data['change_request_id'] = $change_request['change_request_id']; if (isset($_REQUEST['completed_test'])) { if (!isset($_REQUEST['completed']) || !$_REQUEST['completed']) { $data['status'] = _CHANGE_REQUEST_STATUS_NEW; // not completed. } else { $data['status'] = _CHANGE_REQUEST_STATUS_COMPLETE; // completed! } } if (isset($_REQUEST['delete_request'])) { $data['status'] = _CHANGE_REQUEST_STATUS_DELETE; // deleted } $change_request_id = update_insert('change_request_id', $change_request['change_request_id'], 'change_request', $data); // redirect to send email page if we're logged in if (module_security::is_logged_in() && isset($_REQUEST['completed_send_email']) && $_REQUEST['completed_send_email'] && self::can_i('edit', 'Change Requests')) { // don't do the template, do the redirect to the email page (todo!) redirect_browser(self::link_open($change_request_id)); } else { // send email to administrator (everyone with change request edit permissions?) about this change request. $alert_users = module_user::get_users_by_permission(array('category' => 'Change Request', 'name' => 'Change Requests', 'module' => 'change_request', 'edit' => 1)); $email_data = get_single('change_request', 'change_request_id', $change_request_id); $customer_data = $website_data = array(); if ($website_id) { $website_data = module_website::get_website($website_id); $email_data['website_name'] = $website_data['name']; $email_data['website_link'] = module_website::link_open($website_id, true); if ($website_data && $website_data['customer_id']) { $customer_data = module_customer::get_customer($website_data['customer_id'], true); } } if (isset($email_data['request'])) { $email_data['request'] = nl2br($email_data['request']); // for the plain text emails. } foreach ($alert_users as $alert_user) { // todo: make sure this staff member has access to this website? // nfi how to figure this out. maybe we just look for staff members who are assigned jobs/tasks against this website? $template = module_template::get_template_by_key('change_request_alert_email'); $template->assign_values(array_merge($customer_data, $website_data, $email_data)); $html = $template->render('html'); // send an email to this user. $email = module_email::new_email(); $email->replace_values = array_merge($customer_data, $website_data, $email_data); $email->set_to('user', $alert_user['user_id']); $email->set_from('user', module_security::get_loggedin_id() ? module_security::get_loggedin_id() : isset($customer_data['primary_user_id']) ? $customer_data['primary_user_id'] : 0); $email->set_subject($template->description); // do we send images inline? $email->set_html($html); if ($email->send()) { // it worked successfully!! // sweet. } else { /// log err? set_error(_l('Failed to send change notification email to User ID: %s Email: %s Status: %s Error: %s', $alert_user['user_id'], json_encode($email->to), $email->status, $email->error_text)); } } } // display thankyou template. module_template::init_template('change_request_submitted', '<h2>Change Request</h2> <p>Thank you. Your change request has been submitted successfully.</p> <p>Please <a href="{URL}">click here</a> to continue.</p> ', 'Displayed after a change request is created/updated.', 'code'); // correct! // load up the receipt template. $template = module_template::get_template_by_key('change_request_submitted'); $template->page_title = _l("Change Request"); foreach ($data as $key => $val) { if (!is_array($val)) { $data[$key] = htmlspecialchars($val); } } $template->assign_values($data); echo $template->render('pretty_html'); exit; break; case 'display_change': ob_start(); ?> <div class="title"> <?php _e('Change request'); ?> </div> <div class="content"> <p><?php echo nl2br(htmlspecialchars($change_request['request'])); ?> </p> <div class="wp3changerequest_actions"> <p> <!-- <strong><?php _e('Attachments:'); ?> </strong> <?php if (!$change_request['attachments']) { ?> - none - <?php } else { foreach ($change_request['attachments'] as $attachment) { ?> <a href="#"><?php echo htmlspecialchars($attachment->name); ?> </a> <?php } ?> <?php } ?> <br/>--> <strong><?php _e('Created by:'); ?> </strong> <?php echo htmlspecialchars($change_request['name']); ?> <br/> <strong><?php _e('Created on:'); ?> </strong> <?php echo print_date($change_request['date_created'], true); ?> <?php if (isset($change_request['job_id']) && $change_request['job_id']) { ?> <br/> <strong><?php _e('Converted to job:'); ?> </strong> <?php _e('This task has been converted to a Job'); ?> <?php } ?> </p> <?php if (!isset($change_request['job_id']) || !$change_request['job_id'] || self::can_i('edit', 'Change Requests')) { ?> <p align="center"> <input type="button" name="edit" value="<?php _e('Edit'); ?> " class="wp3changerequest_button wp3changerequest_button_small" onclick="dtbaker_changerequest.edit(<?php echo $change_request_id; ?> ); return false;"> </p> <?php } ?> </div> </div> <?php $change_request['html'] = preg_replace('/\\s+/', ' ', ob_get_clean()); // echo json_encode($change_request); // exit; @ob_end_clean(); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Cache-Control: no-cache"); header("Pragma: no-cache"); header("Content-type: text/javascript"); ?> var t = dtbaker_changerequest; var change_id = <?php echo $change_request_id; ?> ; var msg = <?php echo json_encode($change_request); ?> ; jQuery('body').prepend('<div class="wp3changerequest_change" id="dtbaker_change_'+change_id+'" style="'+((!t.show_postits) ? 'display:none;':'')+'"></div>'); var box = jQuery('#dtbaker_change_'+change_id); box.html(msg.html); if(msg.status == 0){ box.addClass('wp3changerequest_change_pending'); }else if(msg.status == 2){ box.addClass('wp3changerequest_change_complete'); }else if(msg.status == 3){ box.addClass('wp3changerequest_change_deleted'); } box.css('top',msg.y+'px'); box.data('window_width',msg.window_width); box.data('left',msg.x); t.set_left(change_id); with({i:change_id}){ jQuery(window).resize(function () { t.set_left(i); }); } box.data('original_height',box.height()); box.css('overflow','hidden'); jQuery('.title',box).slideUp(); box.stop(true, true).animate({ height: t.min_height, width: t.min_width },500); box.hover(function(){ jQuery(this).addClass('wp3changerequest_change_active'); jQuery('.title',this).stop(true, true).slideDown(); jQuery(this).stop().animate({ width: t.max_width, height: jQuery(this).data('original_height'), opacity: 1 },500); },function(){ jQuery('.title',this).stop(true, true).slideUp(); jQuery(this).stop().animate({ width: t.min_width, height: t.min_height, opacity: 0.7 },500,function(){ jQuery(this).removeClass('wp3changerequest_change_active'); }); }) <?php break; default: @ob_end_clean(); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Cache-Control: no-cache"); header("Pragma: no-cache"); header("Content-type: text/javascript"); ob_start(); include 'pages/popup.php'; $html = ob_get_clean(); $html = addcslashes($html, "'"); $html = preg_replace('#\\r|\\n#', "' +\n'", $html); // inject using javascript. fixes cross domain issues ?> if(!jQuery('#dtbaker_changerequest_inlinewizard').length){ // fix for jQuery 1.9+ jQuery('body').append('<div id="dtbaker_changerequest_inlinewizard" style="display:none;"></div>'); } jQuery('#dtbaker_changerequest_inlinewizard').html('<?php echo $html; ?> '); <?php } } exit; break; case 'script': // load up the full script to be injected into our clients website. $website_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false; $hash = isset($_REQUEST['hash']) ? $_REQUEST['hash'] : false; @ob_end_clean(); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Cache-Control: no-cache"); header("Pragma: no-cache"); header("Content-type: text/javascript"); if ($website_id && $hash && module_change_request::link_script($website_id, true) == $hash) { include "js/client.js"; $client_url = isset($_REQUEST['url']) ? $_REQUEST['url'] : false; if ($client_url) { $change_requests = self::get_change_requests(array('website_id' => $website_id, 'url' => $client_url)); // todo - option this out incase url causes issues. ie: old js check method ?> jQuery(function(){ <?php foreach ($change_requests as $change_request) { $displayed = false; if ($change_request['status'] == _CHANGE_REQUEST_STATUS_NEW) { $displayed = true; ?> dtbaker_changerequest.display_change(<?php echo $change_request['change_request_id']; ?> ); <?php } if (isset($_SESSION['_change_request_highlight']) && $_SESSION['_change_request_highlight'] == $change_request['change_request_id']) { ?> <?php if (!$displayed) { ?> dtbaker_changerequest.display_change(<?php echo $change_request['change_request_id']; ?> ); <?php } ?> dtbaker_changerequest.highlight(<?php echo (int) $_SESSION['_change_request_highlight']; ?> ); <?php unset($_SESSION['_change_request_highlight']); } } ?> }); <?php } else { // not posting the URL, some setups do not like this // get list of active change requests $change_requests = self::get_change_requests(array('website_id' => $website_id, 'status' => _CHANGE_REQUEST_STATUS_NEW)); // we also do completed ones because the change request highlight countbe in there $completed_change_requests = self::get_change_requests(array('website_id' => $website_id, 'status' => _CHANGE_REQUEST_STATUS_COMPLETE)); ?> jQuery(function(){ var current_url = window.location.href; <?php foreach ($change_requests as $change_request) { ?> if(current_url == '<?php echo addcslashes(htmlspecialchars($change_request['url']), "'"); ?> '){ // todo: do this better! dtbaker_changerequest.display_change(<?php echo $change_request['change_request_id']; ?> ); } <?php } ?> <?php // todo: do we display all previous change requests on the page or not? if (isset($_SESSION['_change_request_highlight']) && $_SESSION['_change_request_highlight']) { echo '// Checking for request: ' . (int) $_SESSION['_change_request_highlight']; foreach ($completed_change_requests as $complete_change_request) { if ($complete_change_request['change_request_id'] == $_SESSION['_change_request_highlight']) { // show this completed one as well. ?> dtbaker_changerequest.display_change(<?php echo $complete_change_request['change_request_id']; ?> ); <?php } } ?> dtbaker_changerequest.highlight(<?php echo (int) $_SESSION['_change_request_highlight']; ?> ); <?php // todo: move this unset over to the "display_change" callback so we only remove the session when we know it has been displayed. unset($_SESSION['_change_request_highlight']); } ?> }); <?php } } exit; break; case 'public': $website_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false; $hash = isset($_REQUEST['hash']) ? $_REQUEST['hash'] : false; if ($website_id && $hash && module_change_request::link_public($website_id, true) == $hash) { // correct! // redirect to website with our "change_request" url parameter, that is picked up by the included text. $website = module_website::get_website($website_id); $change_request_website = get_single('change_request_website', 'website_id', $website_id); if ($change_request_website && $change_request_website['enabled']) { $url = module_website::urlify($website['url']); // todo - pass this to a (yet to be created) method in website that will deal with https:// or http:// based on user input. stop hardcoding http! if (isset($_REQUEST['change_request_id'])) { $selected_change_request = self::get_change_request_by_website($website_id, (int) $_REQUEST['change_request_id']); if ($selected_change_request && $selected_change_request['url']) { $url = $selected_change_request['url']; } //$url .= "&change_request_id=".(int)$_REQUEST['change_request_id']; $_SESSION['_change_request_highlight'] = (int) $_REQUEST['change_request_id']; } $url = $url . (strpos($url, '?') === false ? '?' : '&') . 'change_request=' . self::link_script($website_id, true); redirect_browser($url); } } echo "Change request disabled."; break; } }
/** START TABLE LAYOUT **/ $table_manager = module_theme::new_table_manager(); $columns = array(); $columns['website_name'] = array('title' => 'Name', 'callback' => function ($website) { echo module_website::link_open($website['website_id'], true, $website); }, 'cell_class' => 'row_action'); if (module_config::c('project_display_url', 1)) { $columns['website_url'] = array('title' => 'URL', 'callback' => function ($website) { if (strlen(trim($website['url'])) > 0) { ?> <a href="<?php echo module_website::urlify($website['url']); ?> " target="_blank"><?php echo module_website::urlify($website['url']); ?> </a> <?php } }); } if (!isset($_REQUEST['customer_id']) && module_customer::can_i('view', 'Customers')) { $columns['website_customer'] = array('title' => 'Customer', 'callback' => function ($website) { echo module_customer::link_open($website['customer_id'], true); }); } $columns['website_status'] = array('title' => 'Status', 'callback' => function ($website) { echo htmlspecialchars($website['status']); }); if (class_exists('module_group', false)) {