mirror of https://github.com/itflow-org/itflow
Merge pull request #254 from wrongecho/scheduled-tickets
Scheduled tickets
This commit is contained in:
commit
04ad831053
|
|
@ -0,0 +1,158 @@
|
|||
<div class="modal" id="addScheduledTicketModal" tabindex="-1">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content bg-dark">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-tag"></i> New Scheduled Ticket</h5>
|
||||
<button type="button" class="close text-white" data-dismiss="modal">
|
||||
<span>×</span>
|
||||
</button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<div class="modal-body bg-white">
|
||||
<?php if(isset($_GET['client_id'])){ ?>
|
||||
<input type="hidden" name="client" value="<?php echo $client_id; ?>">
|
||||
<div class="form-group">
|
||||
<label>Contact <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-user"></i></span>
|
||||
</div>
|
||||
<select class="form-control select2" name="contact" required>
|
||||
<option value="">- Contact -</option>
|
||||
<?php
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM contacts WHERE contact_client_id = $client_id ORDER BY contact_name ASC");
|
||||
while($row = mysqli_fetch_array($sql)){
|
||||
$contact_id = $row['contact_id'];
|
||||
$contact_name = $row['contact_name'];
|
||||
?>
|
||||
<option value="<?php echo $contact_id; ?>" <?php if($primary_contact == $contact_id){ echo "selected"; } ?>><?php echo "$contact_name"; ?></option>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<?php }else{ ?>
|
||||
<div class="form-group">
|
||||
<label>Client <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-user"></i></span>
|
||||
</div>
|
||||
<select class="form-control select2" name="client" required>
|
||||
<option value="">- Client -</option>
|
||||
<?php
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM clients WHERE company_id = $session_company_id ORDER BY client_name ASC");
|
||||
while($row = mysqli_fetch_array($sql)){
|
||||
$client_id = $row['client_id'];
|
||||
$client_name = $row['client_name'];
|
||||
?>
|
||||
<option value="<?php echo $client_id; ?>"><?php echo "$client_name"; ?></option>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Frequency <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-thermometer-half"></i></span>
|
||||
</div>
|
||||
<select class="form-control select2" name="frequency" required>
|
||||
<option>Weekly</option>
|
||||
<option>Monthly</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Starting date <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-thermometer-half"></i></span>
|
||||
</div>
|
||||
<input class="form-control" type="date" min="<?php echo date("Y-m-d"); ?>" name="start_date">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Priority <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-thermometer-half"></i></span>
|
||||
</div>
|
||||
<select class="form-control select2" name="priority" required>
|
||||
<option>Low</option>
|
||||
<option>Medium</option>
|
||||
<option>High</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Subject <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-tag"></i></span>
|
||||
</div>
|
||||
<input type="text" class="form-control" name="subject" placeholder="Subject" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Leaving this here for when the functionality is implemented -->
|
||||
<?php if(!empty($config_smtp_host)){ ?>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="custom-control custom-checkbox">
|
||||
<input type="checkbox" class="custom-control-input" id="customControlAutosizing" name="email_ticket_updates" value="1" checked>
|
||||
<label class="custom-control-label" for="customControlAutosizing">Email ticket updates <span class="text-secondary"><?php echo $contact_email; ?></span></label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Asset</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-desktop"></i></span>
|
||||
</div>
|
||||
<select class="form-control select2" name="asset">
|
||||
<option value="0">- None -</option>
|
||||
<?php
|
||||
|
||||
$sql_assets = mysqli_query($mysqli,"SELECT * FROM assets WHERE asset_client_id = $client_id ORDER BY asset_name ASC");
|
||||
while($row = mysqli_fetch_array($sql_assets)){
|
||||
$asset_id_select = $row['asset_id'];
|
||||
$asset_name_select = $row['asset_name'];
|
||||
?>
|
||||
<option value="<?php echo $asset_id_select; ?>"><?php echo $asset_name_select; ?></option>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<textarea class="form-control summernote" rows="8" name="details"></textarea>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer bg-white">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
|
||||
<button type="submit" name="add_scheduled_ticket" class="btn btn-primary">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -55,6 +55,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
|
|||
<h3 class="card-title mt-2"><i class="fa fa-fw fa-tags"></i> Tickets</h3>
|
||||
<div class="card-tools">
|
||||
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addTicketModal"><i class="fas fa-fw fa-plus"></i> New Ticket</button>
|
||||
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addScheduledTicketModal"><i class="fas fa-fw fa-plus"></i> Scheduled Ticket</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
|
|
@ -195,4 +196,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<?php include("add_ticket_modal.php"); ?>
|
||||
<?php
|
||||
include("add_ticket_modal.php");
|
||||
include("add_scheduled_ticket_modal.php");
|
||||
?>
|
||||
|
|
|
|||
60
cron.php
60
cron.php
|
|
@ -32,6 +32,10 @@ while($row = mysqli_fetch_array($sql_companies)){
|
|||
$config_recurring_auto_send_invoice = $row['config_recurring_auto_send_invoice'];
|
||||
$config_base_url = $row['config_base_url'];
|
||||
|
||||
//Tickets
|
||||
$config_ticket_prefix = $row['config_ticket_prefix'];
|
||||
$config_ticket_next_number = $row['config_ticket_next_number'];
|
||||
|
||||
if($config_enable_cron == 1){
|
||||
|
||||
//GET ALERTS
|
||||
|
|
@ -286,6 +290,62 @@ while($row = mysqli_fetch_array($sql_companies)){
|
|||
//Send Alert to inform Cron was run
|
||||
mysqli_query($mysqli,"INSERT INTO alerts SET alert_type = 'Cron', alert_message = 'Cron.php successfully executed', alert_date = NOW(), company_id = $company_id");
|
||||
} //End Cron Check
|
||||
|
||||
// Scheduled tickets
|
||||
// This should really be somewhere else above, but I don't want to break anything. Please move as appropriate.
|
||||
|
||||
// Get date now, and calculate tomorrow's date (presuming this is being run at 11 PM)
|
||||
$now = new DateTime();
|
||||
$tomorrow = date_add($now, date_interval_create_from_date_string('1 day'));
|
||||
$tomorrow_text = $tomorrow->format('Y-m-d');
|
||||
|
||||
// Get scheduled tickets for tomorrow
|
||||
$sql_scheduled_tickets = mysqli_query($mysqli, "SELECT * FROM scheduled_tickets WHERE scheduled_ticket_next_run = '$tomorrow_text'");
|
||||
|
||||
if(mysqli_num_rows($sql_scheduled_tickets) > 0){
|
||||
while($row = mysqli_fetch_array($sql_scheduled_tickets)){
|
||||
$schedule_id = $row['scheduled_ticket_id'];
|
||||
$subject = $row['scheduled_ticket_subject'];
|
||||
$details = $row['scheduled_ticket_details'];
|
||||
$priority = $row['scheduled_ticket_priority'];
|
||||
$frequency = strtolower($row['scheduled_ticket_frequency']);
|
||||
$created_id = $row['scheduled_ticket_created_by'];
|
||||
$client_id = $row['scheduled_ticket_client_id'];
|
||||
$contact_id = $row['scheduled_ticket_contact_id'];
|
||||
$asset_id = $row['scheduled_ticket_asset_id'];
|
||||
$company_id = $row['company_id'];
|
||||
|
||||
//Get the next Ticket Number and add 1 for the new ticket number
|
||||
$ticket_number = $config_ticket_next_number;
|
||||
$new_config_ticket_next_number = $config_ticket_next_number + 1;
|
||||
mysqli_query($mysqli,"UPDATE settings SET config_ticket_next_number = $new_config_ticket_next_number WHERE company_id = '$company_id'");
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO tickets SET ticket_prefix = '$config_ticket_prefix', ticket_number = $ticket_number, ticket_subject = '$subject', ticket_details = '$details', ticket_priority = '$priority', ticket_status = 'Open', ticket_created_at = NOW(), ticket_created_by = $created_id, ticket_contact_id = $contact_id, ticket_client_id = $client_id, ticket_asset_id = $asset_id, company_id = $company_id");
|
||||
|
||||
//Logging
|
||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Ticket', log_action = 'Create', log_description = 'System created scheduled $frequency ticket - $subject', log_created_at = NOW(), log_client_id = $client_id, company_id = $company_id, log_user_id = $created_id");
|
||||
|
||||
//Set the next run date
|
||||
if($frequency == "weekly"){
|
||||
//NOTE: We seemingly have to initialize a new datetime for each loop.
|
||||
//Otherwise it stacks the dates of $now / $tomorrow, e.g. by the third scheduled ticket it will schedule the next run for three weeks/months out instead of one
|
||||
//This isn't clean but it works
|
||||
//TODO: Refactor this
|
||||
$now = new DateTime();
|
||||
$next_run = date_add($now, date_interval_create_from_date_string('1 week 1 day'));
|
||||
}
|
||||
elseif($frequency == "monthly"){
|
||||
$now = new DateTime();
|
||||
$next_run = date_add($now, date_interval_create_from_date_string('1 month 1 day'));
|
||||
}
|
||||
|
||||
//Update the run date
|
||||
$next_run = $next_run->format('Y-m-d');
|
||||
$a = mysqli_query($mysqli, "UPDATE scheduled_tickets SET scheduled_ticket_next_run = '$next_run' WHERE scheduled_ticket_id = '$schedule_id'");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} //End Company Loop through
|
||||
|
||||
?>
|
||||
|
|
|
|||
25
db.sql
25
db.sql
|
|
@ -852,6 +852,31 @@ CREATE TABLE `roles` (
|
|||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `scheduled_tickets`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `scheduled_tickets`;
|
||||
CREATE TABLE IF NOT EXISTS `scheduled_tickets` (
|
||||
`scheduled_ticket_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`scheduled_ticket_category` varchar(200) DEFAULT NULL,
|
||||
`scheduled_ticket_subject` varchar(200) NOT NULL,
|
||||
`scheduled_ticket_details` longtext NOT NULL,
|
||||
`scheduled_ticket_priority` varchar(200) DEFAULT NULL,
|
||||
`scheduled_ticket_frequency` varchar(10) NOT NULL,
|
||||
`scheduled_ticket_start_date` date NOT NULL,
|
||||
`scheduled_ticket_next_run` date NOT NULL,
|
||||
`scheduled_ticket_created_at` datetime NOT NULL,
|
||||
`scheduled_ticket_updated_at` datetime DEFAULT NULL,
|
||||
`scheduled_ticket_created_by` int(11) NOT NULL,
|
||||
`scheduled_ticket_client_id` int(11) DEFAULT NULL,
|
||||
`scheduled_ticket_contact_id` int(11) DEFAULT NULL,
|
||||
`scheduled_ticket_asset_id` int(11) DEFAULT NULL,
|
||||
`company_id` int(11) NOT NULL,
|
||||
PRIMARY KEY (`scheduled_ticket_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
COMMIT;
|
||||
|
||||
--
|
||||
-- Table structure for table `settings`
|
||||
--
|
||||
|
|
|
|||
28
post.php
28
post.php
|
|
@ -4863,6 +4863,34 @@ if(isset($_POST['add_ticket'])){
|
|||
|
||||
}
|
||||
|
||||
if(isset($_POST['add_scheduled_ticket'])){
|
||||
$client_id = intval($_POST['client']);
|
||||
$contact = intval($_POST['contact']);
|
||||
$subject = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['subject'])));
|
||||
$priority = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['priority'])));
|
||||
$details = trim(mysqli_real_escape_string($mysqli,$_POST['details']));
|
||||
$asset_id = intval($_POST['asset']);
|
||||
$frequency = trim(mysqli_real_escape_string($mysqli,$_POST['frequency']));
|
||||
$start_date = mysqli_real_escape_string($mysqli,$_POST['start_date']);
|
||||
|
||||
if($client_id > 0 AND $contact == 0){
|
||||
$sql = mysqli_query($mysqli,"SELECT primary_contact FROM clients WHERE client_id = $client_id AND company_id = $session_company_id");
|
||||
$row = mysqli_fetch_array($sql);
|
||||
$contact = $row['primary_contact'];
|
||||
}
|
||||
|
||||
// Add scheduled ticket
|
||||
mysqli_query($mysqli, "INSERT INTO scheduled_tickets SET scheduled_ticket_subject = '$subject', scheduled_ticket_details = '$details', scheduled_ticket_priority = '$priority', scheduled_ticket_frequency = '$frequency', scheduled_ticket_start_date = '$start_date', scheduled_ticket_next_run = '$start_date', scheduled_ticket_created_at = NOW(), scheduled_ticket_created_by = '$session_user_id', scheduled_ticket_client_id = '$client_id', scheduled_ticket_contact_id = '$contact', scheduled_ticket_asset_id = '$asset_id', company_id = '$session_company_id'");
|
||||
|
||||
//Logging
|
||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Ticket', log_action = 'Create', log_description = 'Created scheduled ticket for $subject $frequency starting $start_date', log_created_at = NOW(), log_client_id = $client_id, company_id = $session_company_id, log_user_id = $session_user_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Scheduled ticket created.";
|
||||
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
|
||||
}
|
||||
|
||||
if(isset($_POST['edit_ticket'])){
|
||||
|
||||
$ticket_id = intval($_POST['ticket_id']);
|
||||
|
|
|
|||
Loading…
Reference in New Issue