7 $self=
"$menu_link?ft=$ft";
9 $parameters= array(
"a" => array(
"gridData" =>
""));
10 $string= array(
"filter" => FILTER_DEFAULT);
11 HCU_ImportVars($parameters,
"a", array(
"gridData" => $string));
12 extract($parameters[
"a"]);
13 $showSQL= $SYSENV[
"devmode"];
19 case "readAfterHours":
24 $records= readAfterHours($dbh, $sqls, $Cu,
true);
28 $returnArray= array(
"error" => array($e->getMessage()),
"sql" => $sqls,
"record" => array());
32 $returnArray= array(
"error" => array(),
"sql" => $sqls,
"record" => $records);
34 case "saveAfterHours":
35 $returnArray= saveAfterHours($dbh, $Cu, $Cn, $gridData);
37 default: $returnArray= array(
"sql" => array(),
"error" => array(
"Operation not recognized: $operation."),
"record" => array());
41 header(
'Content-type: application/json');
43 unset($returnArray[
"sql"]);
44 print json_encode($returnArray);
48 printAfterHoursPage($self);
63 function saveAfterHours($dbh, $Cu, $Cn, $gridData)
69 throw new exception(
"Grid Data is required!", 1);
70 $gridData= HCU_JsonDecode($gridData);
71 if (!is_array($gridData))
72 throw new exception(
"Grid Data is not correct!", 2);
74 $createArray= array();
75 $updateArray= array();
76 $deleteArray= array();
77 $priorityMap= array();
78 foreach($gridData as $record)
80 if (!isset($record[
"contactid"]) || !isset($record[
"priority"]) || !isset($record[
"name"]) || !isset($record[
"phone"]) || !isset($record[
"comments"]))
81 throw new exception(
"gridData is not correct!", 3);
82 if (isset($record[
"removed"]) && $record[
"removed"])
84 if ($record[
"contactid"] == 0)
86 $deleteArray[]= array(
"_action" =>
"delete",
"contactid" => $record[
"contactid"],
"user_name" => strtolower($Cu));
90 $priority= intval($record[
"priority"]);
91 if (isset($priorityMap[$priority]))
92 throw new exception(
"Priority needs to be unique!", 7);
93 $priorityMap[$priority]=
true;
95 $phone= trim($record[
"phone"]);
96 if (!preg_match(
'/^\([0-9]{3}\) [0-9]{3}-[0-9]{4}$/', $phone))
97 throw new exception(
"Phone is not formatted correctly!", 8);
99 $thisRecord= array(
"contactid" => $record[
"contactid"],
"priority" => $priority,
"name" => $record[
"name"],
"phone" => $phone,
100 "comments" => $record[
"comments"],
"user_name" => strtolower($Cu));
101 if ($record[
"contactid"] == 0)
103 $thisRecord[
"_action"]=
"insert";
104 $createArray[]= $thisRecord;
108 $thisRecord[
"_action"]=
"update";
109 $updateArray[]= $thisRecord;
114 $sql=
"select email from cuadminusers where user_name= '$Cn' and cu= '$Cu'";
116 $sth = db_query($sql, $dbh);
118 throw new exception(
"Email query failed!", 6);
119 $email= db_fetch_row($sth)[0];
122 if (count($deleteArray) > 0 && DataAdminTableUpdate($dbh, array(
"cu" => $Cu), array(
"cucontact" => $deleteArray), $Cn,
123 "CCON_DEL",
"notificationMaintenance.prg",
"A",
"Contact removed", $Cn, $email, trim($_SERVER[
"REMOTE_ADDR"])) ===
false)
124 throw new exception(
"Delete audit function failed!", 5);
125 if (count($updateArray) > 0 && DataAdminTableUpdate($dbh, array(
"cu" => $Cu), array(
"cucontact" => $updateArray), $Cn,
126 "CCON_UPD",
"notificationMaintenance.prg",
"A",
"Contact updated", $Cn, $email, trim($_SERVER[
"REMOTE_ADDR"])) ===
false)
127 throw new exception(
"Update audit function failed!", 4);
128 if (count($createArray) > 0 && DataAdminTableUpdate($dbh, array(
"cu" => $Cu), array(
"cucontact" => $createArray), $Cn,
129 "CCON_ADD",
"notificationMaintenance.prg",
"A",
"Contact added", $Cn, $email, trim($_SERVER[
"REMOTE_ADDR"])) ===
false)
130 throw new exception(
"Create audit function failed!", 3);
132 $returnData= readAfterHours($dbh, $sqls, $Cu,
true);
136 return array(
"error" => array($e->getMessage()),
"sql" => $sqls,
"returnData" => array());
138 return array(
"error" => array(),
"sql" => $sqls,
"returnData" => $returnData);
152 function readAfterHours($dbh, &$sqls, $Cu, $editable)
154 $sql=
"select contactid, priority, name, phone, comments from cucontact where user_name = '" . strtolower($Cu) .
"' order by user_name, priority";
156 $sth= db_query($sql, $dbh);
158 throw new exception(
"After Hours Support query failed!", 3);
159 $afterHoursSupport= array();
160 for($i=0; $row= db_fetch_assoc($sth, $i); $i++)
162 $row[
"phone"]= preg_replace(
'/[^0-9]*/',
"", $row[
"phone"]);
165 $length= strlen($row[
"phone"]);
166 $row[
"phone"]= $length == 10 ?
"(" . substr($row[
"phone"], 0, 3) .
") " . substr($row[
"phone"], 3, 3) .
"-" . substr($row[
"phone"], 6)
167 : ($length == 7 ? substr($row[
"phone"], 0, 3) .
"-" . substr($row[
"phone"], 3) :
"");
169 if (trim($row[
"phone"]) ==
"")
170 throw new exception(
"Phone is invalid.", 4);
171 $row[
"name"]= trim($row[
"name"]);
172 $row[
"comments"]= trim($row[
"comments"]);
173 $afterHoursSupport[]= $row;
175 return $afterHoursSupport;
184 function printAfterHoursPage($self)
187 <?php printTopCenterCss(200); ?>
189 <script type=
"text/javascript">
191 getShowWaitFunctions(); ?>
203 var grid= $(
"#grid").kendoGrid({
209 url:
"<?php echo $self; ?>&operation=readAfterHours" 211 parameterMap:
function(data, type)
221 contactid: {type:
"number"},
222 pid: {type:
"number", defaultValue:
function() {
return nextPid++; }},
223 priority: {type:
"number", defaultValue:
function() {
return nextPriority++; }},
224 name: {type:
"string"},
225 phone: {type:
"string", validation: {phone:
function(input) {
226 if (!$(input).is(
"[name='phone']"))
228 if (!$(input).val().trim().match(/^\([0-9]{3}\) [0-9]{3}-[0-9]{4}$/))
230 $(input).attr(
"data-phone-msg",
"Phone Number is invalid!");
235 comments: {type:
"string"},
236 removed: {type:
"boolean", defaultValue:
false},
237 changed: {type:
"boolean", defaultValue:
true}
240 parse:
function(data)
244 if (data.error.length > 0)
245 $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
246 else if (data.record.length > 0)
248 var lastRecord= data.record[data.record.length-1];
249 nextPriority= Number(lastRecord.priority);
250 nextPid= Number(lastRecord.pid);
256 sort: {field:
"priority", dir:
"asc"},
257 filter: {field:
"removed",
operator:
"neq", value:
true}
265 {command: [{name:
"custRemove", text:
"Delete"}]},
266 {field:
"priority", title:
"Priority", editor:
function(container, options) {
267 var oldPriority= options.model.priority;
268 var oldPid= options.model.pid;
269 var gridData= $(
"#grid").data(
"kendoGrid").dataSource.data();
283 for(var i=0; i!= gridData.length; i++)
285 if (gridData[i].removed)
287 var newPriority= gridData[i].priority;
288 var newPid= gridData[i].pid;
289 var difference= newPriority - oldPriority;
290 if (newPriority < oldPriority)
291 ddlOptions.push({text:
"Move up " + (-difference), value: newPriority, pid: newPid});
292 else if (newPriority > oldPriority)
293 ddlOptions.push({text:
"Move down " + difference, value: newPriority, pid: newPid});
297 ddlOptions.sort(
function(a, b) {
298 return (a.value < 0 ? (b.value < 0 ? b.value - a.value : 1) : (b.value >= 0 ? a.value - b.value : -1));
300 if (oldPriority != gridData.length)
301 ddlOptions.unshift({text:
"Move Bottom", value: gridData.length});
302 if (oldPriority != 1)
303 ddlOptions.unshift({text:
"Move Top", value: 1});
304 ddlOptions.unshift({text:
"Keep Priority", value: -1});
306 $(
"<div class='priorityDDL'></div>").appendTo(container).kendoDropDownList({
310 dataTextField:
"text",
311 dataValueField:
"value",
314 var dataItem= this.dataItem();
315 if (dataItem.value == -1)
323 for(var i=0; i!= gridData.length; i++)
325 if (gridData[i].removed)
327 if (oldPid == gridData[i].pid)
329 gridData[i].priority= dataItem.value;
330 gridData[i].changed=
true;
332 else if (dataItem.value <= gridData[i].priority && oldPriority >= gridData[i].priority)
334 gridData[i].priority++;
335 gridData[i].changed=
true;
337 else if (oldPriority <= gridData[i].priority && dataItem.value >= gridData[i].priority)
339 gridData[i].priority--;
340 gridData[i].changed=
true;
343 $(
"#grid").data(
"kendoGrid").dataSource.data(gridData);
345 }).data(
"kendoDropDownList");
347 {field:
"name", title:
"Name", editor:
function(container, options) {
348 var input= $(
"<input type='text' class='k-input k-textbox' name='" + options.field +
"' required data-required-msg='Name is required!' maxlength=35>").appendTo(container);
350 {field:
"phone", title:
"Phone", editor:
function(container, options) {
351 var input= $(
"<input name='" + options.field +
"'>").appendTo(container).kendoMaskedTextBox({
352 mask:
"(000) 000-0000" 353 }).data(
"kendoMaskedTextBox")
355 {field:
"comments", title:
"Comments", width:
"40%", editor:
function(container, options) {
356 var input= $(
"<input type='text' class='k-input k-textbox' name='" + options.field +
"' maxlength=255>").appendTo(container);
359 }).data(
"kendoGrid");
365 $(
"#grid").on(
"click",
".k-grid-custRemove",
function() {
366 $(
"#formInfoDiv").hide();
367 var deleteDialog= $(
"#deleteDialog").data(
"kendoWindow");
368 if (deleteDialog ==
null)
370 var
template=
"<div>\ 372 Are you sure you want to delete this record?\ 375 <a href='\\#' class='k-button okBtn'>Yes</a>\ 376 <a href='\\#' class='k-button cancelBtn'>No</a>\ 380 deleteDialog= $(
"<div id='deleteDialog' style='text-align:left;'></div>").appendTo(
"body").kendoWindow({
392 }).data(
"kendoWindow");
395 $(
"#deleteDialog .okBtn").click(
function() {
396 var grid= $(
"#grid").data(
"kendoGrid");
398 var gridData= grid.dataSource.data();
399 var dataItem= $(
"#deleteDialog").data(
"dataItem");
400 dataItem.removed=
true;
401 dataItem.changed=
true;
403 for(var i=0; i!= gridData.length; i++)
405 if (gridData[i].pid == dataItem.pid || gridData[i].removed)
407 if (gridData[i].priority >= dataItem.priority)
409 gridData[i].changed=
true;
410 gridData[i].priority--;
415 grid.dataSource.data(gridData);
416 deleteDialog.close();
420 $(
"#deleteDialog .cancelBtn").click(
function() {
421 deleteDialog.close();
426 var grid= $(
"#grid").data(
"kendoGrid");
427 $(
"#deleteDialog").data(
"dataItem", grid.dataItem($(
this).closest(
"tr")));
429 activeWindows.push(deleteDialog);
434 $(
"#savePageBtn").click(
function() {
435 $(
"#formInfoDiv").hide();
438 var data= grid.dataSource.data();
439 for(var i=0; i!=data.length; i++)
442 changedData.push({contactid: data[i].contactid, priority: Number(data[i].priority), name: data[i].name, phone: data[i].phone, comments: data[i].comments,
443 removed: data[i].removed});
446 if (changedData.length > 0)
449 $.post(
"<?php echo $self; ?>&operation=saveAfterHours", {gridData: kendo.stringify(changedData)},
function(data) {
451 if (data.error.length > 0)
452 $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
455 $.homecuValidator.displayMessage(
"Changes were saved successfully!", $.homecuValidator.settings.statusInfo );
457 $(
"#grid").data(
"kendoGrid").dataSource.data(data.returnData);
466 var activeWindows= [];
467 $(document).ready(
function() {
469 <?php printClickOverlayEvent(); ?>
472 <div
class=
"container-fluid">
473 <div
id=
"formValidateDiv" class=
"k-block k-error-colored formValidateDiv" style=
"display:none;"></div>
474 <div
class=
"form-horizontal form-widgets">
475 <div
id=
"grid" style=
"margin-bottom: 5px;"></div>
476 <a href=
"#" id=
"savePageBtn" class=
"k-button">Save Changes</a>