6 $monLibrary = dirname(__FILE__) .
"/../library";
7 $sharedLibrary = dirname(__FILE__) .
"/../../shared/library";
8 $billingLibrary = dirname(__FILE__) .
"/../../billing/library";
9 require_once(
"$monLibrary/cu_top.i");
10 require_once(
"$monLibrary/ck_hticket.i");
11 require_once(
"$monLibrary/monitorView.i");
12 require_once(
"$sharedLibrary/commonPhpFunctions.i");
14 require_once(
"$sharedLibrary/errormail.i");
15 require_once(
"$billingLibrary/billingEmailFunctions.i");
16 require_once(
"$billingLibrary/configuration.i");
18 if (!CheckPerm($link, $Hu, basename($_SERVER[
'SCRIPT_NAME']), $_SERVER[
'REMOTE_ADDR'])) {
21 header(
"Location: /hcuadm/hcu_noperm.prg");
25 dms_import_v2($DATA_PARAMETERS,
"TOP_LEVEL", array(
"operation" =>
"string"));
26 $operation = $DATA_PARAMETERS[
"TOP_LEVEL"][
"operation"];
30 $returnArray = ReadCuissues($dbh);
33 $returnArray = ReadIssueEdit($dbh, $Hu);
36 $returnArray = ReadIssueAdd($dbh);
39 $returnArray = SaveIssue($dbh, $Hu,
true);
42 $returnArray = SaveIssue($dbh, $Hu,
false);
45 $returnArray = AddNewContact($dbh);
48 $returnArray = GetComments($dbh, $Hu);
51 $returnArray = ReadTasks($dbh);
54 $returnArray = ModifyTask($dbh,
true, $Hu);
57 $returnArray = ModifyTask($dbh,
false, $Hu);
60 $returnArray = DeleteTask($dbh, $Hu);
62 case "changeTaskStatus":
63 $returnArray = ChangeTaskStatus($dbh, $Hu);
66 $returnArray = ReorderTasks($dbh, $Hu);
68 case "addTaskComment":
69 $returnArray = ModifyTaskComment($dbh, $Hu,
true);
71 case "updateTaskComment":
72 $returnArray = ModifyTaskComment($dbh, $Hu,
false);
75 $returnArray = PromoteTask($dbh, $Hu);
77 case "addIssueFromTemplate":
78 $returnArray = AddIssueFromTemplate($dbh, $Hu);
80 case "deleteTaskComment":
81 $returnArray = DeleteTaskComment($dbh);
83 case "pullInTaskTemplates":
84 $returnArray = PullInTaskTemplates($dbh);
86 case "setReportCookie":
87 $returnArray = SetReportCookie($SYSENV);
89 case "clearReportCookie":
90 $returnArray = ClearReportCookie($SYSENV);
92 default: $returnArray = array(
"error" => array(
"Operation not specified: '$operation'"),
"record" =>
"",
"operation" =>
"");
95 header(
'Content-type: application/json');
96 print HCU_JsonEncode($returnArray);
102 function GetIssueStatuses() {
104 array(
"value" =>
"Active",
"currentStatus" =>
"Active"),
105 array(
"value" =>
"Suspended",
"currentStatus" =>
"Active"),
106 array(
"value" =>
"Completed",
"currentStatus" =>
"Active"),
107 array(
"value" =>
"Deleted",
"currentStatus" =>
"Active"),
108 array(
"value" =>
"Suspended",
"currentStatus" =>
"Suspended"),
109 array(
"value" =>
"Active",
"currentStatus" =>
"Suspended"),
110 array(
"value" =>
"Deleted",
"currentStatus" =>
"Suspended"),
111 array(
"value" =>
"Completed",
"currentStatus" =>
"Completed"),
112 array(
"value" =>
"Active",
"currentStatus" =>
"Completed"),
113 array(
"value" =>
"Suspended",
"currentStatus" =>
"Completed"),
114 array(
"value" =>
"Deleted",
"currentStatus" =>
"Completed"),
115 array(
"value" =>
"Deleted",
"currentStatus" =>
"Deleted"),
116 array(
"value" =>
"Active",
"currentStatus" =>
"Deleted"),
117 array(
"value" =>
"Unrecognized",
"currentStatus" =>
"Unrecognized"),
118 array(
"value" =>
"Active",
"currentStatus" =>
"Unrecognized"),
119 array(
"value" =>
"Suspended",
"currentStatus" =>
"Unrecognized"),
120 array(
"value" =>
"Completed",
"currentStatus" =>
"Unrecognized"),
121 array(
"value" =>
"Deleted",
"currentStatus" =>
"Unrecognized"));
125 function GetTaskStatuses() {
126 return array(
"1" =>
"TODO",
"0" =>
"Done",
"2" =>
"N/A");
130 function GetContactRoles() {
131 global $cu_contact_role;
133 foreach($cu_contact_role as $key => $value) {
134 $roles[] = array(
"text" => $value,
"value" => $key);
142 function ReadCuissues($dbh)
144 $parameters = array();
145 dms_import_v2($parameters,
"BOTTOM_LEVEL", array(
"cu" =>
"string",
"showCompleted" =>
"string",
"setDDLs" =>
"string",
"showDeleted" =>
"string"));
150 $errors= cleanValuesForDatabase($parameters[
"BOTTOM_LEVEL"],
151 array(
"cu" => array(
"type" =>
"string",
"required" =>
false,
"maxlength" => 12),
152 "showCompleted" => array(
"type" =>
"boolean",
"required" =>
false),
153 "showDeleted" => array(
"type" =>
"boolean",
"required" =>
false),
154 "setDDLs" => array(
"type" =>
"boolean",
"required" =>
false)));
156 $cu= strtoupper($parameters[
"BOTTOM_LEVEL"][
"cu"]);
157 $showCompleted= $parameters[
"BOTTOM_LEVEL"][
"showCompleted"] ==
"Y";
158 $showDeleted= $parameters[
"BOTTOM_LEVEL"][
"showDeleted"] ==
"Y";
159 $setDDLs= $parameters[
"BOTTOM_LEVEL"][
"setDDLs"] ==
"Y";
162 $notStatusArray= array();
163 $completeDatePiece=
"";
166 $completeDatePiece=
"and t.complete_date is null";
167 $notStatusArray[]=
"Completed";
168 $notStatusArray[]=
"Billed";
171 $notStatusArray[]=
"Deleted";
172 if (count($notStatusArray) > 0)
173 $where[]=
"t.status not in ('" . implode(
"', '", $notStatusArray) .
"') $completeDatePiece";
175 $where[]=
"upper(t.user_name) = '$cu'";
176 $whereSQL= count($where) == 0 ?
"" :
"where (" . implode(
") and (", $where) .
")";
178 $sql=
"select t.track_id, temp.number, t.user_name, t.issue, t.status, t.assigned_to, t.contact, t.entry_date, t.last_activity_date, i.name, temp.title, temp.assigned_to as tassigned_to, 179 t.target_date, t.target_date_type, t.billing_feature_id, t.drop_dead_date, t.issue_id from cutrack t inner join cuinfo i on lower(t.user_name)= lower(i.user_name) 180 left join (select row_number() over (partition by ti.track_id, ti.parent order by ti.view_order, ti.trackitem_id) as number, ti.title, ti.assigned_to, ti.track_id 181 from cutrackitem ti where ti.task_status <> 2 and ti.complete_date is null and ti.parent = 0) temp on t.track_id= temp.track_id and temp.number = 1 $whereSQL";
182 $sqlResults= runSelectStatement($sql, $dbh, array(
"track_id" =>
"trackId",
"user_name" =>
"cuCode",
"issue" =>
"issue",
"assigned_to" =>
"issueOwner",
"entry_date" =>
"entryDate",
183 "target_date_type" =>
"targetDateType",
"last_activity_date" =>
"lastActivityDate",
"name" =>
"cuName",
"title" =>
"nextTask",
"tassigned_to" =>
"nextTaskOwner",
184 "status" =>
"status",
"target_date" =>
"targetDate",
"billing_feature_id" =>
"billingFeatureId",
"drop_dead_date" =>
"dropDeadDate",
"issue_id" =>
"issueId"));
186 $cloneSQL=
"select distinct ti.track_id, '|cloneJob|' from cutrackitem ti where lower(ti.title) like '%clone a server%' and ti.complete_date is null and ti.task_status <> 2";
187 $cloneMapResults= runSelectStatementMap($cloneSQL, $dbh);
189 $unattachedSQL=
"select t.track_id, '|unattached|' from cutrack t left join cubillfeaturedetail fd on t.billing_feature_id = fd.id where fd.id is null";
190 $unattachedMapResults= runSelectStatementMap($unattachedSQL, $dbh);
192 $records= $sqlResults[
"record"];
193 for($i=0, $count=count($records); $i != $count; $i++)
195 $trackId= $records[$i][
"trackId"];
196 $issueId= $records[$i][
"issueId"];
198 switch(trim(strtoupper($records[$i][
"targetDateType"])))
201 $records[$i][
"targetDateTypeSort"]= 1;
204 $records[$i][
"targetDateTypeSort"]= 3;
207 $records[$i][
"targetDateTypeSort"]= 2;
210 $records[$i][
"targetDateTypeSort"]= 4;
216 if (HCU_array_key_exists($trackId, $cloneMapResults[
'record'])) {
217 $records[$i][
"jobType"]= strval($cloneMapResults[
"record"][$trackId]) . strval($unattachedMapResults[
"record"][$trackId]) . (in_array($issueId, array(35, 10, 20, 5)) ?
"|imp|" :
"");
221 $ddlSQL=
"select issue_id, code from cuissues order by code";
222 $ddlResults= runSelectStatement($ddlSQL, $dbh, array(
"issue_id" =>
"value",
"code" =>
"text"));
224 global $SYS_TYPE_CLOSED;
225 $cuSQL=
"select i.user_name, i.name from cuinfo i where i.system_options & $SYS_TYPE_CLOSED = 0 order by i.user_name";
226 $cuResults= runSelectStatement($cuSQL, $dbh, array(
"user_name" =>
"value",
"name" =>
"cuName"));
228 $errors= array_merge($errors, $sqlResults[
"error"], $cloneMapResults[
"error"], $ddlResults[
"error"], $cuResults[
"error"]);
229 $sqls= array($sql, $cloneSQL, $unattachedSQL, $ddlSQL, $cuSQL);
232 foreach($cuResults[
"record"] as $record)
234 $record[
"text"]= $record[
"cuName"] .
" (" . $record[
"value"] .
")";
238 return array(
"error" => $errors,
"sql" => $sqls,
"operation" =>
"read",
"record" => $records,
"templateDDL" => $ddlResults[
"record"],
"cuDDL" => $cuDDL);
242 function readIssueEdit($dbh, $staffId)
244 $parameters= array();
245 dms_import_v2($parameters,
"BOTTOM_LEVEL", array(
"trackId" =>
"string",
"cu" =>
"string"));
247 $errors= cleanValuesForDatabase($parameters[
"BOTTOM_LEVEL"],
248 array(
"trackId" => array(
"type" =>
"int",
"required" =>
true)));
249 $trackId= $parameters[
"BOTTOM_LEVEL"][
"trackId"];
251 $sql=
"select t.track_id, t.user_name, t.issue, t.status, t.assigned_to, t.entry_date, t.last_activity_date, t.next_contact_date, t.contact_id, i.name, t.issue_id, t.contact, t.contact_phone, 252 t.contact_email, t.notes, t.target_date, t.complete_date, t.target_date_type, i.www_server, i.vendor, t.billing_feature_id, t.drop_dead_date, ci.gen_for_product, fd.id as test_id, 254 from cutrack t inner join cuinfo i on lower(t.user_name)= lower(i.user_name) left join cuissues ci on t.issue_id = ci.issue_id 255 left join cubillfeaturedetail fd on t.billing_feature_id = fd.id 256 where t.track_id= $trackId";
257 $results= runSelectStatement($sql, $dbh, array(
"track_id" =>
"trackId",
"name" =>
"cuName",
"user_name" =>
"cu",
"issue" =>
"issue",
"status" =>
"status",
"assigned_to" =>
"issueOwner",
258 "last_activity_date" =>
"lastActivity",
"entry_date" =>
"enteredOn",
"target_date" =>
"targetDate",
"complete_date" =>
"completedOn",
259 "contact_id" =>
"contactId",
"target_date_type" =>
"targetDateType",
"issue_id" =>
"templateId",
"www_server" =>
"server",
"vendor" =>
"vendor",
260 "contact" =>
"contactName",
"contact_phone" =>
"contactPhone",
"contact_email" =>
"contactEmail",
"notes" =>
"oldComments",
261 "billing_feature_id" =>
"billingFeatureId",
"drop_dead_date" =>
"dropDeadDate",
"gen_for_product" =>
"product",
"billed" =>
"billed",
262 "test_id" =>
"testId"));
263 $errors= array_merge($errors, $results[
"error"]);
265 if (count($errors) == 0 && count($results[
"record"]) == 0)
267 $errors[]=
"Issue with track id provided does not exist.";
273 $record= $results[
"record"][0];
277 $commentsSQL=
"select row_number() over(order by messageid) as number, n.messageid, n.author, n.createddate, n.messagetext, n.activitydate, n.trackitem_id, ti.title from cuinfo_notes n 278 left join cutrackitem ti on n.trackitem_id = ti.trackitem_id where n.track_id = $trackId";
280 $results= runSelectStatement($commentsSQL, $dbh,
281 array(
"messageid" =>
"commentId",
"author" =>
"author",
"createddate" =>
"createdDate",
"messagetext" =>
"text",
"number" =>
"mockCommentId",
282 "trackitem_id" =>
"trackItemId",
"title" =>
"trackItemName"));
284 $comments= $results[
"record"];
285 for($i=0, $count=count($comments); $i != $count; $i++)
287 $comments[$i][
"groupId"]= intval($comments[$i][
"trackItemId"]) == 0 ? 0 : 1;
289 $errors= array_merge($errors, $results[
"error"]);
291 $returnArray= array(
"error" => $errors,
"sql" => array($sql, $commentsSQL),
"operation" =>
"read",
"record" => $record,
"comments" => $comments);
292 getIssueDDLs($dbh, $returnArray, $cu, $record[
"contactName"], $record[
"contactPhone"], $record[
"contactEmail"], $record[
"product"]);
294 $returnArray[
"selectSpecial"]= ($record[
"contactName"] !=
"" && $record[
"contactId"] ==
"0") || ($record[
"contactId"] ==
"-1");
300 function readIssueAdd($dbh)
302 $parameters= array();
303 dms_import_v2($parameters,
"BOTTOM_LEVEL", array(
"cu" =>
"string"));
306 $errors= cleanValuesForDatabase($parameters[
"BOTTOM_LEVEL"], array(
"cu" => array(
"type" =>
"string",
"required" =>
false,
"maxlength" => 12)));
307 $returnArray= array(
"error" => $errors,
"sql" => array(),
"operation" =>
"read");
308 $cu= $parameters[
"BOTTOM_LEVEL"][
"cu"];
309 getIssueDDLs($dbh, $returnArray, $cu);
310 $returnArray[
"selectSpecial"]=
false;
315 function getIssueDDLs($dbh, &$returnArray, $cu, $contactName=
"", $contactPhone=
"", $contactEmail=
"", $product=
"")
317 global $SYS_TYPE_CLOSED;
318 $cu= strtoupper($cu);
319 $cuSQL=
"select i.user_name, i.name, i.www_server, i.vendor from cuinfo i where upper(i.user_name) = '$cu' or i.system_options & $SYS_TYPE_CLOSED = 0 order by i.user_name";
320 $cuResults= runSelectStatement($cuSQL, $dbh, array(
"user_name" =>
"value",
"name" =>
"text",
"www_server" =>
"server",
"vendor" =>
"vendor"));
322 $ownerSQL=
"select u.user_name from dmsmonitorusers u order by lower(u.user_name)";
323 $ownerResults= runSelectStatement($ownerSQL, $dbh, array(
"user_name" =>
"value"));
325 $contactSQL=
"select c.id, coalesce(c.fname, '') || ' ' || coalesce(c.lname, '') as full_name, c.phone, c.email, c.user_name from monitor_contact c";
327 $contactSQL.=
" where upper(c.user_name) = '$cu'";
328 $contactResults= runSelectStatement($contactSQL, $dbh, array(
"id" =>
"contactId",
"full_name" =>
"text",
"phone" =>
"phone",
"email" =>
"email",
"user_name" =>
"cu"));
330 $contactDDL= $contactResults[
"record"];
332 for($i=0, $count=count($contactDDL); $i != $count; $i++)
334 $contactDDL[$i][
"sortNumber"]= 3;
337 array_unshift($contactDDL,
338 array(
"contactId" =>
"",
"text" =>
"NONE",
"fullName" =>
"",
"phone" =>
"",
"email" =>
"",
"cu" =>
"",
"sortNumber" => 0),
339 array(
"contactId" =>
"",
"text" =>
"NEW",
"fullName" =>
"",
"phone" =>
"",
"email" =>
"",
"cu" =>
"",
"sortNumber" => 1),
340 array(
"contactId" =>
"-1",
"text" =>
"SPECIAL",
"fullName" => $contactName,
"phone" => $contactPhone,
"email" => $contactEmail,
"cu" =>
"",
"sortNumber" => 2));
342 $ownerDDL= $ownerResults[
"record"];
343 for($i=0, $count=count($ownerDDL); $i != $count; $i++)
345 $ownerDDL[$i][
"text"]= $ownerDDL[$i][
"value"];
346 $ownerDDL[$i][
"filterNumber"]= 0;
349 array_unshift($ownerDDL, array(
"value" =>
"",
"text" =>
"(Job Owner)",
"filterNumber" => 1), array(
"value" =>
"",
"text" =>
"(Parent Owner)",
"filterNumber" => 2));
351 $returnArray[
"error"]= array_merge($returnArray[
"error"], $cuResults[
"error"], $ownerResults[
"error"], $contactResults[
"error"]);
352 $returnArray[
"cuDDL"]= $cuResults[
"record"];
353 $returnArray[
"ownerDDL"]= $ownerDDL;
354 $returnArray[
"statusDDL"]= getIssueStatuses();
355 $returnArray[
"contactDDL"]= $contactDDL;
356 $returnArray[
"roleDDL"]= getContactRoles();
358 $taskStatusDDL= array();
359 foreach(getTaskStatuses() as $value => $text)
361 $taskStatusDDL[]= array(
"text" => $text,
"value" => $value);
363 $returnArray[
"taskStatusDDL"]= $taskStatusDDL;
365 $unattachedFeatureDetailsSQL=
"select fd.id, si.display_name, coalesce(p.home_cu_desc, cd.prod_id) as prod_desc, c.cu_id, si.billing_system_id from cubillfeaturedetail fd 366 inner join cubillsalesorderdetail cd on fd.sales_order_detail_id = cd.id inner join cubillsalesorder c on cd.sales_order_id = c.id inner join cubillsalesitem si on fd.sales_item_id = si.id 367 left join cuprodlist p on si.prod_id = p.home_cu_code left join cutrack t on fd.id = t.billing_feature_id";
368 $where= array(
"t.track_id is null");
370 $where[]=
"upper(c.cu_id) = '$cu'";
372 $where[]=
"cd.prod_id = '$product'";
373 $unattachedFeatureDetailsSQL.=
" where (" . implode(
") and (", $where) .
")";
375 $returnArray[
"sql"]= array_merge($returnArray[
"sql"], array($cuSQL, $ownerSQL, $contactSQL, $unattachedFeatureDetailsSQL));
377 $results= runSelectStatement($unattachedFeatureDetailsSQL, $dbh, array(
"id" =>
"value",
"display_name" =>
"itemDesc",
"prod_desc" =>
"prodDesc",
"cu_id" =>
"cu",
378 "billing_system_id" =>
"billingSystemId"));
379 $returnArray[
"error"]= array_merge($returnArray[
"error"], $results[
"error"]);
380 $sqls[]= $unattachedFeatureDetailsSQL;
381 $unattachedFeatureDetailsDDL= array();
382 $setupRecurring= getSetupRecurring();
383 foreach($results[
"record"] as $record)
385 $isSetup= trim($setupRecurring[$record[
"billingSystemId"]]) ==
"setup";
387 $unattachedFeatureDetailsDDL[]= array(
"text" => strval($record[
"prodDesc"]) .
": " . strval($record[
"itemDesc"]),
"value" => $record[
"value"],
"cu" => strtolower($record[
"cu"]));
389 array_unshift($unattachedFeatureDetailsDDL, array(
"text" =>
"(None)",
"value" =>
"",
"cu" =>
""));
390 $returnArray[
"unattachedFeatureDetailsDDL"]= $unattachedFeatureDetailsDDL;
394 foreach($cuResults[
"record"] as $record)
396 if (strtoupper($record[
"value"]) == $cu)
398 $returnArray[
"cuName"]= $record[
"text"];
408 function saveIssue($dbh, $staffId, $isAdd)
410 $parameters= array();
412 $allowed= array(
"contactId" =>
"string",
"issue" =>
"string",
"status" =>
"string",
"owner" =>
"string",
"targetDate" =>
"string",
"comments" =>
"string",
"deletedCommentIds" =>
"string",
413 "cu" =>
"string",
"cuName" =>
"string",
"targetDateType" =>
"string",
"contactName" =>
"string",
"contactPhone" =>
"string",
"contactEmail" =>
"string",
"billingFeatureId" =>
"string",
414 "dropDeadDate" =>
"string");
417 $allowed[
"changedIssue"]=
"string";
418 $allowed[
"changedStatus"]=
"string";
419 $allowed[
"changedOwner"]=
"string";
420 $allowed[
"targetDateChanged"]=
"string";
421 $allowed[
"trackId"]=
"digits";
422 $allowed[
"changedContactId"]=
"string";
423 $allowed[
"changedDropDeadDate"]=
"string";
426 dms_import_v2($parameters,
"BOTTOM_LEVEL", $allowed);
428 $cu= strtolower($parameters[
"BOTTOM_LEVEL"][
"cu"]);
429 $cuName= $parameters[
"BOTTOM_LEVEL"][
"cuName"];
430 $issue= $parameters[
"BOTTOM_LEVEL"][
"issue"];
431 $status= $parameters[
"BOTTOM_LEVEL"][
"status"];
432 $comments= $parameters[
"BOTTOM_LEVEL"][
"comments"];
435 $errors= cleanValuesForDatabase($parameters[
"BOTTOM_LEVEL"],
436 array(
"cu" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 12),
437 "cuName" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 40),
438 "contactId" => array(
"type" =>
"int",
"required" =>
false,
"allowNegatives" =>
true),
439 "issue" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 90),
440 "status" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 40),
441 "owner" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 30),
442 "targetDate" => array(
"type" =>
"date",
"required" =>
false),
443 "trackId" => array(
"type" =>
"int",
"required" =>
true),
444 "deletedCommentIds" => array(
"type" =>
"string",
"required" =>
false),
445 "changedIssue" => array(
"type" =>
"boolean",
"required" =>
false),
446 "changedStatus" => array(
"type" =>
"boolean",
"required" =>
false),
447 "changedOwner" => array(
"type" =>
"boolean",
"required" =>
false),
448 "targetDateChanged" => array(
"type" =>
"boolean",
"required" =>
false),
449 "changedContactId" => array(
"type" =>
"boolean",
"required" =>
false),
450 "targetDateType" => array(
"type" =>
"string",
"required" =>
false,
"maxlength" => 10),
451 "contactName" => array(
"type" =>
"string",
"required" =>
false,
"maxlength" => 80),
452 "contactPhone" => array(
"type" =>
"phone",
"required" =>
false,
"maxlength" => 20),
453 "contactEmail" => array(
"type" =>
"email",
"required" =>
false,
"maxlength" => 50),
454 "billingFeatureId" => array(
"type" =>
"int",
"required" =>
false),
455 "dropDeadDate" => array(
"type" =>
"date",
"required" =>
false),
456 "changedDropDeadDate" => array(
"type" =>
"boolean",
"required" =>
false)));
457 $cuClean= strtolower($parameters[
"BOTTOM_LEVEL"][
"cu"]);
458 $contactId= $parameters[
"BOTTOM_LEVEL"][
"contactId"];
459 $issueClean= $parameters[
"BOTTOM_LEVEL"][
"issue"];
460 $statusClean= $parameters[
"BOTTOM_LEVEL"][
"status"];
461 $owner= $parameters[
"BOTTOM_LEVEL"][
"owner"];
462 $targetDate= strval($parameters[
"BOTTOM_LEVEL"][
"targetDate"]);
463 $trackId= isset($parameters[
"BOTTOM_LEVEL"][
"trackId"]) ? intval($parameters[
"BOTTOM_LEVEL"][
"trackId"]) : 0;
464 $deletedCommentIds= $parameters[
"BOTTOM_LEVEL"][
"deletedCommentIds"];
465 $changedIssue= isset($parameters[
"BOTTOM_LEVEL"][
"changedIssue"]) ? ($parameters[
"BOTTOM_LEVEL"][
"changedIssue"] ==
"Y") :
false;
466 $changedStatus= isset($parameters[
"BOTTOM_LEVEL"][
"changedStatus"]) ? ($parameters[
"BOTTOM_LEVEL"][
"changedStatus"] ==
"Y") :
false;
467 $changedOwner= isset($parameters[
"BOTTOM_LEVEL"][
"changedOwner"]) ? ($parameters[
"BOTTOM_LEVEL"][
"changedOwner"] ==
"Y") :
false;
468 $changedTargetDate= isset($parameters[
"BOTTOM_LEVEL"][
"targetDateChanged"]) ? ($parameters[
"BOTTOM_LEVEL"][
"targetDateChanged"] ==
"Y") :
false;
469 $changedContactId= isset($parameters[
"BOTTOM_LEVEL"][
"changedContactId"]) ? ($parameters[
"BOTTOM_LEVEL"][
"changedContactId"] ==
"Y") :
false;
470 $targetDateType= strval($parameters[
"BOTTOM_LEVEL"][
"targetDateType"]);
471 $contactPhone= $parameters[
"BOTTOM_LEVEL"][
"contactPhone"];
472 $contactEmail= $parameters[
"BOTTOM_LEVEL"][
"contactEmail"];
473 $contactName= $parameters[
"BOTTOM_LEVEL"][
"contactName"];
474 $billingFeatureId= $parameters[
"BOTTOM_LEVEL"][
"billingFeatureId"];
475 $dropDeadDate= isset($parameters[
"BOTTOM_LEVEL"][
"dropDeadDate"]) ? $parameters[
"BOTTOM_LEVEL"][
"dropDeadDate"] :
"";
476 $changedDropDeadDate= isset($parameters[
"BOTTOM_LEVEL"][
"changedDropDeadDate"]) ? ($parameters[
"BOTTOM_LEVEL"][
"changedDropDeadDate"] ==
"Y") :
false;
478 if (
false === array_search($targetDateType, array(
"",
"TBD",
"FLEX")))
479 $errors[]=
"Target Date Type is not recognized.";
481 $contactId= $contactId ==
"" ?
"null" : intval($contactId);
482 $targetDate = $targetDate ==
"" ?
"null" :
"'$targetDate'";
483 $targetDateType= $targetDateType ==
"" ?
"null" :
"'$targetDateType'";
484 $contactPhone= $contactPhone ==
"" ?
"null" :
"'$contactPhone'";
485 $contactEmail= $contactEmail ==
"" ?
"null" :
"'$contactEmail'";
486 $contactName= $contactName ==
"" ?
"null" :
"'$contactName'";
487 $dropDeadDate= $dropDeadDate ==
"" ?
"null" :
"'$dropDeadDate'";
489 $transactionSQLs= array();
490 $issueEmails= array();
494 if (($targetDate ==
"null" && $targetDateType ==
"null") || ($targetDate !=
"null" && $targetDateType !=
"null"))
495 $errors[]=
"Target Date and Target Date Type are out of sync.";
497 $execSQL=
"select nextval('cutrack_track_id_seq'::text::regclass) as next";
499 $execResults= runSelectStatement($execSQL, $dbh, array(
"next" =>
"next"));
500 $trackId= intval($execResults[
"record"][0][
"next"]);
501 $errors= array_merge($errors, $execResults[
"error"]);
503 $transactionSQLs[]=
"insert into cutrack (track_id, user_name, issue, status, assigned_to, contact_id, contact, contact_phone, contact_email, target_date, target_date_type, 504 drop_dead_date, entry_date, last_activity_date) values ($trackId, '$cuClean', '$issueClean', '$statusClean', '$owner', $contactId, $contactName, $contactPhone, $contactEmail, $targetDate, 505 $targetDateType, $dropDeadDate, now(), now())";
514 $updateList= array();
515 if ($changedContactId)
517 $updateList[]=
"contact_id= $contactId";
518 if ($contactId ==
"null" || $contactId ==
"-1")
520 $updateList[]=
"contact= $contactName";
521 $updateList[]=
"contact_phone= $contactPhone";
522 $updateList[]=
"contact_email= $contactEmail";
527 $updateList[]=
"issue= '$issueClean'";
530 $updateList[]=
"status= '$statusClean'";
531 if ($status ==
"Active")
533 else if ($status ==
"Completed")
536 $updateList[]=
"complete_date= now()";
538 else if ($status ==
"Deleted")
541 $updateList[]=
"billing_feature_id=0";
543 $startOfMonth=
new DateTime();
544 $startOfMonth= $startOfMonth->format(
"Y-m-01");
547 "update cubillfeaturedetail set billing_status= case when partially_billed_date is not null and partially_billed_date < '$startOfMonth' then 548 5 else 4 end from cutrack t where billing_status=1 and cubillfeaturedetail.id= t.billing_feature_id and t.track_id= $trackId";
551 if (!$nowComplete && !$nowDelete)
552 $updateList[]=
"complete_date= null";
556 $updateList[]=
"assigned_to = '$owner'";
558 if ($changedDropDeadDate)
559 $updateList[]=
"drop_dead_date = $dropDeadDate";
560 if ($changedTargetDate)
563 if (($targetDate ==
"null" && $targetDateType ==
"null") || ($targetDate !=
"null" && $targetDateType !=
"null"))
564 $errors[]=
"Target Date and Target Date Type are out of sync.";
565 $updateList[]=
"target_date = $targetDate, target_date_type = $targetDateType";
567 if ($billingFeatureId !=
"")
569 $updateList[]=
"billing_feature_id=$billingFeatureId";
570 $transactionSQLs[]=
"update cubillfeaturedetail set billing_status= case when billing_status = 5 or partially_billed_date is null then 1 else 0 end where id= $billingFeatureId";
574 $transactionSQLs[]=
"update cutrackitem set billing_item_id= coalesce(fd.id, 0) from cutrackitem ti inner join cutrack t on ti.track_id= t.track_id and t.track_id= $trackId 575 left join cuissuesitem ii on ti.issue_item_id= ii.item_id and ii.issue_id= t.issue_id left join cubillfeaturedetail tfd on tfd.id= $billingFeatureId left join cubillfeaturedetail fd 576 on fd.sales_order_detail_id= tfd.sales_order_detail_id and fd.sales_item_id= ii.sales_item_id where ti.trackitem_id= cutrackitem.trackitem_id";
580 if (count($updateList) != 0 || $comments !=
"" || $comments !=
"[]" || $deletedCommentIds !=
"" || $deletedCommentIds !=
"[]")
582 $updateList[]=
"last_activity_date= now()";
583 $transactionSQLs[]=
"update cutrack set " . implode(
", ", $updateList) .
" where track_id= $trackId";
587 updateBilling($dbh, $trackId, $transactionSQLs);
589 $sql=
"select trackitem_id, billing_item_id from cutrackitem where track_id = $trackId and billing_item_id <> 0 and complete_date is null";
590 $results= runSelectStatementMap($sql, $dbh);
592 $errors= array_merge($errors, $results[
"error"]);
594 foreach($results[
"record"] as $key => $value)
596 updateBillingTaskTrigger($dbh,
"", $value, $transactionSQLs);
600 $dateChangeText= array();
601 if ($changedDropDeadDate)
603 $date=
new DateTime(str_replace(
"'",
"", $dropDeadDate));
604 $dateChangeText[]=
"<b>Drop Dead Date</b> was changed to " . $date->format(
"m/d/Y") .
".";
606 if ($changedTargetDate)
608 if ($targetDateType !=
"null")
609 $formattedDate= $targetDateType;
612 $date=
new DateTime(str_replace(
"'",
"", $targetDate));
613 $formattedDate= $date->format(
"m/d/Y");
615 $dateChangeText[]=
"<b>Target Date</b> was changed to $formattedDate.";
617 if (count($dateChangeText) > 0 && $staffId != $owner) {
618 $results = CreateToLine($dbh, array(trim($owner)));
619 if ($results[
"status"] !==
"000") {
620 $errors[] = $results[
"error"];
622 $issueEmails[] = array(
"to" => $results[
"data"],
"subject" =>
"Job dates were changed!",
"text" => implode(
"<br />", $dateChangeText),
623 "issueName" => $issueClean,
"issueId" => $trackId,
"status" => $status);
630 $comments= json_decode($comments,
true);
631 if (is_array($comments))
633 foreach($comments as $comment)
635 $theseErrors= cleanValuesForDatabase($comment,
636 array(
"commentId" => array(
"type" =>
"int",
"required" =>
false),
637 "text" => array(
"type" =>
"string",
"required" =>
false)));
638 $commentId= intval($comment[
"commentId"]);
639 $text= $comment[
"text"];
641 $text= $text ==
"" ?
"null" :
"'$text'";
643 $errors= array_merge($errors, $theseErrors);
646 $transactionSQLs[]=
"insert into cuinfo_notes (messagetext, cu, author, createddate, activitydate, trackitem_id, track_id) values ($text, '$cu', '$staffId', now(), now(), 0, $trackId)";
648 $transactionSQLs[]=
"update cuinfo_notes set messagetext= $text, activitydate= now() where messageid= $commentId";
653 $errors[]=
"Comments do not form a valid array";
657 if ($deletedCommentIds !=
"")
659 $idArray= json_decode($deletedCommentIds,
true);
660 if (is_array($idArray))
662 if (count($idArray) > 0)
664 foreach($idArray as $id)
666 $cleanedId= cleanInteger($id);
667 if ($cleanedId ==
"ERROR")
669 $errors[]=
"deletedCommentIds has some invalid ids";
674 $transactionSQLs[]=
"delete from cuinfo_notes where messageid in (" . implode(
", ", $idArray) .
")";
678 $errors[]=
"ignoreIds is not a valid array";
682 if (strtolower($staffId) != strtolower($owner)) {
683 if ($isAdd || $changedOwner) {
685 $results = CreateToLine($dbh, array(trim($owner)));
686 if ($results[
"status"] !==
"000") {
687 $errors[] = $results[
"error"];
689 $subject =
"Owner changed!";
690 $text =
"Congratulations! You are the next owner of the job!";
691 $issueEmails[] = array(
"to" => $results[
"data"],
"subject" => $subject,
"text" => $text,
692 "issueName" => $issue,
"issueId" => $trackId,
"status" => $status);
696 $sqls= array_merge($sqls, $transactionSQLs);
697 if (count($errors) == 0) {
698 $results = runExecStatement(implode(
";", $transactionSQLs) .
";", $dbh);
699 $errors = array_merge($errors, $results[
"error"]);
700 if (count($errors) == 0) {
701 foreach($issueEmails as $issueEmail) {
702 CreateIssueEmail($issueEmail[
"to"], $issueEmail[
"subject"], $issueEmail[
"text"], $issueEmail[
"issueName"], $issueEmail[
"status"],
703 $cuName, $cu, $issueEmail[
"issueId"]);
711 return array(
"error" => $errors,
"sql" => $sqls,
"trackId" => $trackId);
715 function addNewContact($dbh)
717 $parameters= array();
718 dms_import_v2($parameters,
"BOTTOM_LEVEL",
719 array(
"firstName" =>
"string",
"lastName" =>
"string",
"role" =>
"string",
"phone" =>
"string",
"email" =>
"string",
"comment" =>
"string",
"decider" =>
"string",
"cu" =>
"string"));
721 $errors= cleanValuesForDatabase($parameters[
"BOTTOM_LEVEL"],
722 array(
"firstName" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 40),
723 "lastName" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 25),
724 "role" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 10),
725 "phone" => array(
"type" =>
"phone",
"required" =>
false),
726 "email" => array(
"type" =>
"email",
"required" =>
false,
"maxlength" => 50),
727 "decider" => array(
"type" =>
"boolean",
"required" =>
false),
728 "comment" => array(
"type" =>
"string",
"required" =>
false),
729 "cu" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 12)));
731 $firstName= $parameters[
"BOTTOM_LEVEL"][
"firstName"];
732 $lastName= $parameters[
"BOTTOM_LEVEL"][
"lastName"];
733 $role= $parameters[
"BOTTOM_LEVEL"][
"role"];
734 $phone= $parameters[
"BOTTOM_LEVEL"][
"phone"];
735 $email= $parameters[
"BOTTOM_LEVEL"][
"email"];
736 $decider= $parameters[
"BOTTOM_LEVEL"][
"decider"];
737 $comment= $parameters[
"BOTTOM_LEVEL"][
"comment"];
738 $cu= strtolower($parameters[
"BOTTOM_LEVEL"][
"cu"]);
740 $fullName=
"$firstName $lastName";
741 $firstName= $firstName ==
"" ?
"null" :
"'$firstName'";
742 $lastName= $lastName ==
"" ?
"null" :
"'$lastName'";
743 $role= $role ==
"" ?
"null" :
"'$role'";
744 $phone= $phone ==
"" ?
"null" :
"'$phone'";
745 $email= $email ==
"" ?
"null" :
"'$email'";
746 $decider= $decider ==
"" ?
"null" :
"'$decider'";
747 $comment= $comment ==
"" ?
"null" :
"'$comment'";
748 $cu= $cu ==
"" ?
"null" :
"'$cu'";
751 $insertSQL=
"insert into monitor_contact (fname, lname, role, phone, email, decider, comment, user_name) values ($firstName, $lastName, $role, $phone, $email, $decider, $comment, $cu); 752 select currval('monitor_contact_id_seq'::regclass) as next;";
753 $returnArray= array(
"sql" => array($insertSQL),
"error" => $errors,
"operation" =>
"add");
754 if (count($errors) == 0)
756 $results= runSelectStatement($insertSQL, $dbh, array(
"next" =>
"next"));
757 $returnArray[
"error"]= $results[
"error"];
758 $contactId= intval($results[
"record"][0][
"next"]);
760 $returnArray[
"newDDLRecord"]= array(
"contactId" => $contactId,
"text" => $fullName,
"phone" => $parameters[
"BOTTOM_LEVEL"][
"phone"],
"email" => $parameters[
"BOTTOM_LEVEL"][
"email"],
761 "cu" => $parameters[
"BOTTOM_LEVEL"][
"cu"],
"sortNumber" => 3);
768 function getComments($dbh, $staffId)
770 $parameters= array();
771 dms_import_v2($parameters,
"BOTTOM_LEVEL",
772 array(
"getAll" =>
"string",
"trackId" =>
"string",
"trackItemId" =>
"string",
"ignoreIds" =>
"string"));
774 $errors= cleanValuesForDatabase($parameters[
"BOTTOM_LEVEL"],
775 array(
"getAll" => array(
"type" =>
"boolean",
"required" =>
false),
776 "trackId" => array(
"type" =>
"int",
"required" =>
true),
777 "trackItemId" => array(
"type" =>
"int",
"required" =>
false),
778 "ignoreIds" => array(
"type" =>
"string",
"required" =>
false)));
780 $getAll= $parameters[
"BOTTOM_LEVEL"][
"getAll"] ==
"Y";
781 $trackId= $parameters[
"BOTTOM_LEVEL"][
"trackId"];
782 $trackItemId= $parameters[
"BOTTOM_LEVEL"][
"trackItemId"];
783 $ignoreIds= $parameters[
"BOTTOM_LEVEL"][
"ignoreIds"];
786 $trackItemId= intval($trackItemId);
787 $trackItemIdSQLPiece= $trackItemId == 0 ? ($getAll ?
"" :
"and trackitem_id= 0") :
"and trackitem_id = $trackItemId";
789 $insensitiveStaffId= strtolower($staffId);
790 $authorSQLPiece= $getAll ?
"" :
"and lower(author) = '$insensitiveStaffId'";
791 $limitIdsSQLPiece=
"";
793 if ($ignoreIds !=
"")
795 $idArray= json_decode($ignoreIds,
true);
796 if (is_array($idArray))
798 if (count($idArray) > 0)
800 foreach($idArray as $id)
802 $cleanedId= cleanInteger($id);
803 if ($cleanedId ==
"ERROR")
805 $errors[]=
"ignoreIds has some invalid ids";
810 $limitIdsSQLPiece=
"and messageid not in (" . implode(
", ", $idArray) .
")";
814 $errors[]=
"ignoreIds is not a valid array";
817 $commentsSQL=
"select row_number() over(order by messageid) as number, messageid, author, createddate, messagetext, trackitem_id from cuinfo_notes 818 where track_id = $trackId $trackItemIdSQLPiece $authorSQLPiece $limitIdsSQLPiece order by createddate";
821 if (count($errors) == 0)
823 $results= runSelectStatement($commentsSQL, $dbh, array(
"messageid" =>
"commentId",
"author" =>
"author",
"createddate" =>
"createdDate",
"messagetext" =>
"text",
824 "trackitem_id" =>
"trackItemId",
"number" =>
"mockCommentId"));
825 $errors= $results[
"error"];
826 $record= $results[
"record"];
828 return array(
"sql" => array($commentsSQL),
"error" => $errors,
"record" => $record,
"operation" =>
"read");
832 function readTasks($dbh)
834 $parameters= array();
835 dms_import_v2($parameters,
"BOTTOM_LEVEL", array(
"trackId" =>
"string"));
837 $errors= cleanValuesForDatabase($parameters[
"BOTTOM_LEVEL"],
838 array(
"trackId" => array(
"type" =>
"int",
"required" =>
true)));
840 $trackId= $parameters[
"BOTTOM_LEVEL"][
"trackId"];
842 $sql=
"select i.trackitem_id, i.title, i.item_desc, i.complete_date, i.task_status, i.parent, i.assigned_to, i.last_status_changed, 843 row_number() over(partition by i.parent order by i.view_order, i.trackitem_id) - 1 as position, i.issue_item_id, i.billing_item_id 844 from cutrackitem i where i.track_id= $trackId order by i.parent, i.task_status, i.view_order, i.trackitem_id";
846 $taskTemplatesSQL=
"select ii.item_id, ii.title from cuissuesitem ii inner join cutrack t on ii.issue_id = t.issue_id and t.track_id= $trackId";
847 $sqls= array($taskTemplatesSQL, $sql);
849 $newRecords= array();
850 $masterTasks= array();
851 if (count($errors) == 0)
853 $taskResults= runSelectStatement($taskTemplatesSQL, $dbh, array(
"item_id" =>
"taskTemplateId",
"title" =>
"title"));
854 $masterTasks= $taskResults[
"record"];
856 $results= runSelectStatement($sql, $dbh, array(
"trackitem_id" =>
"taskId",
"title" =>
"title",
"item_desc" =>
"description",
"complete_date" =>
"completedOn",
"position" =>
"position",
857 "task_status" =>
"statusId",
"parent" =>
"parentTaskId",
"assigned_to" =>
"ownerId",
"last_status_changed" =>
"statusChangedDate",
858 "issue_item_id" =>
"taskTemplateId",
"billing_item_id" =>
"billingItemId"));
859 $errors= array_merge($taskResults[
"error"], $results[
"error"]);
860 $taskStatuses= getTaskStatuses();
862 $newRecords= array();
864 foreach($results[
"record"] as $record)
866 $record[
"statusName"]= $taskStatuses[$record[
"statusId"]];
867 $newRecords[]= $record;
871 return array(
"record" => $newRecords,
"operation" =>
"read",
"error" => $errors,
"sql" => $sqls,
"masterTasks" => $masterTasks);
875 function ModifyTask($dbh, $isAdd, $staffId)
877 $parameters= array();
878 $allowed= array(
"title" =>
"string",
"description" =>
"string",
"ownerId" =>
"string",
"issueId" =>
"string",
"issueOwnerId" =>
"string",
879 "cu" =>
"string",
"cuName" =>
"string",
"issue" =>
"string",
"parentTaskOwnerId" =>
"string",
"isNextTask" =>
"string",
"isFirstTask" =>
"string");
882 $allowed[
"parentTaskId"]=
"string";
883 $allowed[
"position"]=
"string";
887 $allowed[
"taskId"]=
"string";
888 $allowed[
"previousOwnerId"]=
"string";
891 dms_import_v2($parameters,
"BOTTOM_LEVEL", $allowed);
893 $title= $parameters[
"BOTTOM_LEVEL"][
"title"];
894 $description= $parameters[
"BOTTOM_LEVEL"][
"description"];
895 $issue= $parameters[
"BOTTOM_LEVEL"][
"issue"];
896 $cuCode= strtolower($parameters[
"BOTTOM_LEVEL"][
"cu"]);
897 $cuName= $parameters[
"BOTTOM_LEVEL"][
"cuName"];
898 $parentTaskOwnerId= trim($parameters[
"BOTTOM_LEVEL"][
"parentTaskOwnerId"]);
899 $ownerId= trim($parameters[
"BOTTOM_LEVEL"][
"ownerId"]);
900 $issueOwnerId= trim($parameters[
"BOTTOM_LEVEL"][
"issueOwnerId"]);
901 $previousOwnerId= isset($parameters[
"BOTTOM_LEVEL"][
"previousOwnerId"]) ? trim($parameters[
"BOTTOM_LEVEL"][
"previousOwnerId"]) :
"";
903 $errors= cleanValuesForDatabase($parameters[
"BOTTOM_LEVEL"],
904 array(
"title" => array(
"required" =>
false,
"type" =>
"string",
"maxlength" => 80),
905 "description" => array(
"required" =>
false,
"type" =>
"string"),
906 "taskId" => array(
"required" =>
true,
"type" =>
"int"),
907 "issueId" => array(
"required" =>
true,
"type" =>
"int"),
908 "ownerId" => array(
"required" =>
false,
"type" =>
"string",
"maxlength" => 12),
909 "parentTaskId" => array(
"required" =>
false,
"type" =>
"int"),
910 "issueOwnerId" => array(
"required" =>
true,
"type" =>
"string",
"maxlength" => 30),
911 "previousOwnerId" => array(
"required" =>
false,
"type" =>
"string",
"maxlength" => 12),
912 "cu" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 12),
913 "cuName" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 40),
914 "issue" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 90),
915 "position" => array(
"type" =>
"int",
"required" =>
true),
916 "isNextTask" => array(
"type" =>
"boolean",
"required" =>
false),
917 "isFirstTask" => array(
"type" =>
"boolean",
"required" =>
false)));
919 $titleClean= $parameters[
"BOTTOM_LEVEL"][
"title"];
920 $descriptionClean= $parameters[
"BOTTOM_LEVEL"][
"description"];
921 $taskId= isset($parameters[
"BOTTOM_LEVEL"][
"taskId"]) ? intval($parameters[
"BOTTOM_LEVEL"][
"taskId"]) : 0;
922 $issueId= $parameters[
"BOTTOM_LEVEL"][
"issueId"];
923 $ownerIdClean= $parameters[
"BOTTOM_LEVEL"][
"ownerId"];
924 $parentTaskId= isset($parameters[
"BOTTOM_LEVEL"][
"parentTaskId"]) ? intval($parameters[
"BOTTOM_LEVEL"][
"parentTaskId"]) : 0;
925 $position= isset($parameters[
"BOTTOM_LEVEL"][
"position"]) ? $parameters[
"BOTTOM_LEVEL"][
"position"] : 0;
926 $isNextTask= $parameters[
"BOTTOM_LEVEL"][
"isNextTask"] ==
"Y";
927 $isFirstTask= $parameters[
"BOTTOM_LEVEL"][
"isFirstTask"] ==
"Y";
929 $titleForDatabase= $title ==
"" ?
"null" :
"'$titleClean'";
930 $descriptionForDatabase= $description ==
"" ?
"null" :
"'$descriptionClean'";
932 $transactionSQLs= array();
935 if (count($errors) == 0)
939 $sql=
"select nextval('cutrackitem_trackitem_id_seq'::text::regclass) as next";
942 $results= runSelectStatement($sql, $dbh, array(
"next" =>
"next"));
943 $taskId= intval($results[
"record"][0][
"next"]);
945 $transactionSQLs[]=
"insert into cutrackitem (trackitem_id, title, item_desc, assigned_to, track_id, parent, view_order, last_status_changed) 946 values ($taskId, $titleForDatabase, $descriptionForDatabase, '$ownerIdClean', $issueId, $parentTaskId, $position, now())";
951 $transactionSQLs[]=
"update cutrack set previous_task_owner= '$ownerIdClean' where track_id= $issueId";
956 $transactionSQLs[]=
"update cutrackitem set title=$titleForDatabase, item_desc=$descriptionForDatabase, assigned_to='$ownerIdClean' where trackitem_id=$taskId";
959 $transactionSQLs[]=
"update cutrack set last_activity_date= now() where track_id= $issueId";
962 $sqls= array_merge($sqls, $transactionSQLs);
964 if (count($errors) == 0)
966 $results= runExecStatement(implode(
";", $transactionSQLs) .
";", $dbh);
967 $errors= array_merge($errors, $results[
"error"]);
972 $ownerId= $parentTaskOwnerId;
974 $ownerId= $issueOwnerId;
976 if ($isNextTask && !$isAdd && strtolower($ownerId) != strtolower($staffId) && count($errors) == 0) {
977 if ($isAdd || $ownerId != $previousOwnerId) {
979 $text =
"Congratulations! $staffId has assigned a task to you. Please work on this task.";
980 $text2 =
"If you have any questions, please contact $issueOwnerId.";
982 $results = CreateToLine($dbh, array(trim($ownerId)));
983 if ($results[
"status"] !==
"000") {
984 $errors[] = $results[
"error"];
986 $subject =
"You have been assigned a task!";
988 CreateTaskEmail($results[
"data"], $subject, $text, $issue, $title, $description, $cuName, $cuCode, $issueId, $taskId, $text2);
992 $requerySQL=
"select i.trackitem_id, i.title, i.item_desc, i.complete_date, i.task_status, i.parent, i.assigned_to, i.last_status_changed, i.billing_item_id from cutrackitem i 993 where i.trackitem_id= $taskId";
994 $sqls[]= $requerySQL;
995 $requeryResults= runSelectStatement($requerySQL, $dbh, array(
"trackitem_id" =>
"taskId",
"title" =>
"title",
"item_desc" =>
"description",
"complete_date" =>
"completedOn",
996 "task_status" =>
"statusId",
"parent" =>
"parentTaskId",
"assigned_to" =>
"ownerId",
"last_status_changed" =>
"statusChangedDate",
"billing_item_id" =>
"billingItemId"));
997 $errors= array_merge($errors, $requeryResults[
"error"]);
1000 $taskStatuses= getTaskStatuses();
1001 if (isset($requeryResults[
"record"][0]))
1003 $record= $requeryResults[
"record"][0];
1004 $record[
"statusName"]= $taskStatuses[$record[
"statusId"]];
1005 $record[
"position"]= $record[
"taskId"];
1006 $records[]= $record;
1009 return array(
"record" => $records,
"sql" => $sqls,
"error" => $errors,
"operation" => $isAdd ?
"add" :
"update");
1013 function deleteTask($dbh, $staffId)
1015 $parameters= array();
1016 dms_import_v2($parameters,
"BOTTOM_LEVEL", array(
"taskId" =>
"string",
"deleteSubTasks" =>
"string",
"cu" =>
"string",
"cuName" =>
"string",
"isNew" =>
"string",
1017 "trackId" =>
"string"));
1019 $cu= strtoupper($parameters[
"BOTTOM_LEVEL"][
"cu"]);
1020 $cuName= $parameters[
"BOTTOM_LEVEL"][
"cuName"];
1022 $errors= cleanValuesForDatabase($parameters[
"BOTTOM_LEVEL"],
1023 array(
"taskId" => array(
"required" =>
true,
"type" =>
"int"),
1024 "deleteSubTasks" => array(
"required" =>
false,
"type" =>
"boolean"),
1025 "cu" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 12),
1026 "cuName" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 40),
1027 "isNew" => array(
"required" =>
false,
"type" =>
"boolean"),
1028 "trackId" => array(
"required" =>
true,
"type" =>
"int"),
1029 "issue" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 90)));
1030 $taskId= $parameters[
"BOTTOM_LEVEL"][
"taskId"];
1031 $deleteSubTasks= $parameters[
"BOTTOM_LEVEL"][
"deleteSubTasks"] ==
"Y";
1032 $isNew= $parameters[
"BOTTOM_LEVEL"][
"isNew"] ==
"Y";
1033 $issueId= intval($parameters[
"BOTTOM_LEVEL"][
"trackId"]);
1037 if ($taskId == 0 && $deleteSubTasks)
1038 $errors[]=
"Not allowed to delete all top-level tasks.";
1040 $transactionSQLs= array();
1042 $transactionSQLs[]=
"delete from cutrackitem where trackitem_id = $taskId";
1043 $transactionSQLs[]=
"delete from cutrackitem where parent = $taskId";
1044 $transactionSQLs[]=
"update cutrack set last_activity_date= now() where track_id= $issueId";
1046 $taskEmails= array();
1047 $issueEmails= array();
1049 notifyNextTaskOwner($dbh, $issueId, $taskId, $staffId,
"deleted",
null, $errors, $transactionSQLs, $taskEmails, $issueEmails);
1051 $sqls= array_merge($sqls, $transactionSQLs);
1053 if (count($errors) == 0)
1055 $results= runExecStatement(implode(
";", $transactionSQLs) .
";", $dbh);
1056 $errors= array_merge($errors, $results[
"error"]);
1057 if (count($errors) == 0)
1059 foreach($taskEmails as $taskEmail)
1061 createTaskEmail($taskEmail[
"to"], $taskEmail[
"subject"], $taskEmail[
"text"], $taskEmail[
"issue"], $taskEmail[
"title"], $taskEmail[
"description"], $cuName, $cu,
1062 $taskEmail[
"issueId"], $taskEmail[
"taskId"],
"", $taskEmail[
"completeNotes"]);
1064 foreach($issueEmails as $issueEmail)
1066 createIssueEmail($issueEmail[
"to"], $issueEmail[
"subject"], $issueEmail[
"text"], $issueEmail[
"issue"], $issueEmail[
"status"], $cuName, $cu, $issueEmail[
"issueId"],
1067 "", $issueEmail[
"completeNotes"]);
1072 return array(
"error" => $errors,
"sql" => $sqls,
"operation" =>
"delete");
1076 function changeTaskStatus($dbh, $staffId)
1078 $parameters= array();
1080 dms_import_v2($parameters,
"BOTTOM_LEVEL", array(
"taskId" =>
"string",
"newStatus" =>
"string",
"prevStatus" =>
"string",
"issueId" =>
"string",
"issueOwnerId" =>
"string",
1081 "parentTaskId" =>
"string",
"cu" =>
"string",
"cuName" =>
"string",
"nextTaskId" =>
"string",
"nextTaskOwnerChanged" =>
"string",
"nextTaskOwner" =>
"string",
1082 "completeNotes" =>
"string",
"forceEmail" =>
"string",
"completeDate" =>
"string",
"billingItemId" =>
"string"));
1084 $cu= strtoupper($parameters[
"BOTTOM_LEVEL"][
"cu"]);
1085 $cuName= $parameters[
"BOTTOM_LEVEL"][
"cuName"];
1087 $completeNotes= $parameters[
"BOTTOM_LEVEL"][
"completeNotes"];
1089 $errors= cleanValuesForDatabase($parameters[
"BOTTOM_LEVEL"],
1090 array(
"taskId" => array(
"required" =>
true,
"type" =>
"int"),
1091 "newStatus" => array(
"required" =>
true,
"type" =>
"int"),
1092 "prevStatus" => array(
"required" =>
true,
"type" =>
"int"),
1093 "issueId" => array(
"required" =>
true,
"type" =>
"int"),
1094 "issueOwnerId" => array(
"required" =>
true,
"type" =>
"string",
"maxlength" => 30),
1095 "isNew" => array(
"required" =>
false,
"type" =>
"boolean"),
1096 "parentTaskId" => array(
"required" =>
true,
"type" =>
"int"),
1097 "cu" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 12),
1098 "cuName" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 40),
1099 "nextTaskId" => array(
"type" =>
"int",
"required" =>
false),
1100 "nextTaskOwnerChanged" => array(
"type" =>
"boolean",
"required" =>
false),
1101 "nextTaskOwner" => array(
"type" =>
"string",
"required" =>
false,
"maxlength" => 30),
1102 "completeNotes" => array(
"type" =>
"string",
"required" =>
false),
1103 "forceEmail" => array(
"type" =>
"boolean",
"required" =>
false),
1104 "completeDate" => array(
"type" =>
"date",
"required" =>
false),
1105 "billingItemId" => array(
"type" =>
"int",
"required" =>
false)));
1107 $taskId= $parameters[
"BOTTOM_LEVEL"][
"taskId"];
1108 $newStatus= $parameters[
"BOTTOM_LEVEL"][
"newStatus"];
1109 $prevStatus= $parameters[
"BOTTOM_LEVEL"][
"prevStatus"];
1110 $issueId= $parameters[
"BOTTOM_LEVEL"][
"issueId"];
1111 $issueOwnerId= $parameters[
"BOTTOM_LEVEL"][
"issueOwnerId"];
1112 $isNew= isset($parameters[
"BOTTOM_LEVEL"][
"isNew"]) ? ($parameters[
"BOTTOM_LEVEL"][
"isNew"] ==
"Y") :
false;
1113 $parentTaskId= $parameters[
"BOTTOM_LEVEL"][
"parentTaskId"];
1114 $nextTaskOwnerChanged= $parameters[
"BOTTOM_LEVEL"][
"nextTaskOwnerChanged"] ==
"Y";
1115 $nextTaskOwner= $parameters[
"BOTTOM_LEVEL"][
"nextTaskOwner"];
1116 $completeNotesClean= $parameters[
"BOTTOM_LEVEL"][
"completeNotes"];
1117 $forceEmail= $parameters[
"BOTTOM_LEVEL"][
"forceEmail"] ==
"Y";
1118 $nextTaskId= $parameters[
"BOTTOM_LEVEL"][
"nextTaskId"];
1119 $cuClean= strtolower($parameters[
"BOTTOM_LEVEL"][
"cu"]);
1120 $completeDate= $parameters[
"BOTTOM_LEVEL"][
"completeDate"];
1121 $billingItemId= intval($parameters[
"BOTTOM_LEVEL"][
"billingItemId"]);
1123 $taskEmails= array();
1124 $issueEmails= array();
1127 $transactionSQLs= array();
1129 $completeDateSafe =
"";
1130 if ($completeDate !=
"" && count($errors) == 0)
1132 if (count($errors) == 0)
1134 $completeDateTime=
new DateTime($completeDate);
1135 $completeDateSafe= $completeDateTime->format(
"m/d/Y");
1139 $completeDateSafe=
"ERROR";
1143 $statuses= getTaskStatuses();
1144 $statusName= $statuses[$newStatus];
1145 if (!isset($statusName))
1146 $errors[]=
"Status code doesn't exist";
1148 $completeDatePiece= $statusName ==
"Done" ? ($completeDate !=
"" ?
"complete_date = '$completeDate', " :
"complete_date = now(), ") :
"complete_date = null, ";
1149 $completeDatePieceOther= $completeDate !=
"" ?
"'$completeDate'" :
"now()";
1150 $transactionSQLs[]=
"update cutrackitem set $completeDatePiece task_status = $newStatus where trackitem_id = $taskId";
1151 $status= $newStatus;
1152 $noteRecord= array();
1155 if ($parentTaskId != 0)
1157 if ($statusName !=
"TODO")
1159 $transactionSQLs[]=
"update cutrackitem set complete_date = $completeDatePieceOther, task_status = 0 where trackitem_id = $parentTaskId and not exists 1160 (select 'FOUND' from cutrackitem where parent = $parentTaskId and task_status = 1 and trackitem_id <> $taskId)";
1164 $transactionSQLs[]=
"update cutrackitem set complete_date = null, task_status = 1 where trackitem_id = $parentTaskId";
1167 else if ($statusName ==
"Done")
1170 $findChildrenSQL=
"select trackitem_id, billing_item_id from cutrackitem where parent = $taskId and complete_date is null";
1171 $results= runSelectStatementMap($findChildrenSQL, $dbh);
1172 $sqls[]= $findChildrenSQL;
1173 $errors= array_merge($errors, $results[
"error"]);
1175 if (count(array_keys($results[
"record"])) > 0)
1177 foreach($results[
"record"] as $key => $value)
1180 updateBillingTaskTrigger($dbh, $completeDate, $value, $transactionSQLs);
1183 $transactionSQLs[]=
"update cutrackitem set complete_date = $completeDatePieceOther, task_status = 0 where parent = $taskId";
1187 if ($nextTaskId !=
"" && $nextTaskOwnerChanged)
1189 $transactionSQLs[]=
"update cutrackitem set assigned_to='$nextTaskOwner' where trackitem_id = $nextTaskId";
1193 if ($completeNotes !=
"")
1195 $noteRecord= array(
"author" => $staffId,
"text" => $completeNotes,
"trackItemId" => $taskId);
1197 $sql=
"select nextval('cuinfo_notes_messageid_seq'::text::regclass) as next";
1199 $results= runSelectStatement($sql, $dbh, array(
"next" =>
"next"));
1200 $errors= array_merge($errors, $results[
"error"]);
1201 $commentId= intval($results[
"record"][0][
"next"]);
1202 $noteRecord[
"commentId"]= $commentId;
1204 $transactionSQLs[]=
"insert into cuinfo_notes (messageid, trackitem_id, track_id, messagetext, cu, author, createddate, activitydate) 1205 values ($commentId, $taskId, $issueId, '$completeNotesClean', '$cuClean', '$staffId', now(), now())";
1208 if ($billingItemId != 0)
1210 updateBillingTaskTrigger($dbh, $completeDate, $billingItemId, $transactionSQLs);
1213 else if ($statusName ==
"N/A")
1215 $transactionSQLs[]=
"update cutrackitem set complete_date= null, task_status = 2 where parent = $taskId";
1218 $transactionSQLs[]=
"update cutrack set last_activity_date= now() where track_id= $issueId";
1226 $mode=
"inactivated";
1229 $mode=
"reactivated";
1233 notifyNextTaskOwner($dbh, $issueId, $taskId, $staffId, $mode, $issueOwnerId, $errors, $transactionSQLs, $taskEmails, $issueEmails, $completeNotes,
1234 $forceEmail, $reassigned);
1236 $sqls= array_merge($sqls, $transactionSQLs);
1237 if (count($errors) == 0)
1239 $results= runExecStatement(implode(
";", $transactionSQLs) .
";", $dbh);
1240 $errors= array_merge($errors, $results[
"error"]);
1242 if (count($errors) == 0)
1244 foreach($taskEmails as $taskEmail)
1246 createTaskEmail($taskEmail[
"to"], $taskEmail[
"subject"], $taskEmail[
"text"], $taskEmail[
"issue"], $taskEmail[
"title"], $taskEmail[
"description"], $cuName, $cu,
1247 $taskEmail[
"issueId"], $taskEmail[
"taskId"],
"", $taskEmail[
"completeNotes"]);
1249 foreach($issueEmails as $issueEmail)
1251 createIssueEmail($issueEmail[
"to"], $issueEmail[
"subject"], $issueEmail[
"text"], $issueEmail[
"issue"], $issueEmail[
"status"], $cuName, $cu, $issueEmail[
"issueId"],
1252 "", $issueEmail[
"completeNotes"]);
1257 if (count($errors) > 0)
1259 $status= $prevStatus;
1260 $statusName= $statuses[$prevStatus];
1263 $returnArray= array(
"error" => $errors,
"sql" => $sqls,
"statusId" => $status,
"statusName" => $statusName,
"completeDate" => trim($completeDateSafe));
1265 if ($completeNotes !=
"")
1266 $returnArray[
"noteRecord"]= $noteRecord;
1268 return $returnArray;
1271 function updateBillingTaskTrigger($dbh, $completeDate, $billingItemId, &$transactionSQLs)
1276 $thisDate= trim($completeDate) ==
"" ?
new DateTime() : new DateTime($completeDate);
1277 $m= $thisDate->format(
"m");
1278 $Y= $thisDate->format(
"Y");
1279 $thisDate->setDate($Y, $m, 1);
1280 $tryMonth1= $thisDate->format(
"Y-m-d");
1281 $thisDate->setDate($Y, $m+1, 1);
1282 $tryMonth2= $thisDate->format(
"Y-m-d");
1286 $tryMonth1=
"ERROR";
1287 $tryMonth2=
"ERROR";
1290 $transactionSQLs[]=
"update cubillfeaturedetail set start_date= t.date, end_date= t.date, billing_status=2, workflow_completed='Y' from 1291 (select case when not exists (select 'FOUND' from cubillmonth where billing_date='$tryMonth1') then date '$tryMonth1' else date '$tryMonth2' end) as t (date) 1292 where cubillfeaturedetail.id= $billingItemId and cubillfeaturedetail.workflow_completed= 'N'";
1296 function reorderTasks($dbh, $staffId)
1298 $parameters= array();
1299 dms_import_v2($parameters,
"BOTTOM_LEVEL", array(
"taskIds" =>
"string",
"issueId" =>
"string",
"isNew" =>
"string",
"parentTaskId" =>
"string",
"cu" =>
"string",
"cuName" =>
"string",
1300 "taskId" =>
"string",
"moveTaskId" =>
"string",
"moveAfter" =>
"string"));
1302 $cu= $parameters[
"BOTTOM_LEVEL"][
"cu"];
1303 $cuName= $parameters[
"BOTTOM_LEVEL"][
"cuName"];
1305 $errors= cleanValuesForDatabase($parameters[
"BOTTOM_LEVEL"], array(
"taskIds" => array(
"required" =>
true,
"type" =>
"string"),
1306 "issueId" => array(
"required" =>
true,
"type" =>
"int"),
1307 "isNew" => array(
"required" =>
false,
"type" =>
"boolean"),
1308 "parentTaskId" => array(
"required" =>
true,
"type" =>
"int"),
1309 "cu" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 12),
1310 "cuName" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 40),
1311 "taskId" => array(
"type" =>
"int",
"required" =>
true),
1312 "moveTaskId" => array(
"type" =>
"int",
"required" =>
true),
1313 "moveAfter" => array(
"type" =>
"boolean",
"required" =>
false)));
1314 $taskIds= json_decode($parameters[
"BOTTOM_LEVEL"][
"taskIds"],
true);
1315 $issueId= $parameters[
"BOTTOM_LEVEL"][
"issueId"];
1316 $isNew= $parameters[
"BOTTOM_LEVEL"][
"isNew"] ==
"Y";
1317 $parentTaskId= $parameters[
"BOTTOM_LEVEL"][
"parentTaskId"];
1318 $moveAfter= $parameters[
"BOTTOM_LEVEL"][
"moveAfter"] ==
"Y";
1319 $taskId= $parameters[
"BOTTOM_LEVEL"][
"taskId"];
1320 $moveTaskId= $parameters[
"BOTTOM_LEVEL"][
"moveTaskId"];
1323 $transactionSQLs= array();
1324 $taskEmails= array();
1325 $issueEmails= array();
1327 if (is_array($taskIds))
1329 $sqlPartArray= array();
1333 foreach($taskIds as $taskId)
1335 $taskId= cleanInteger($taskId);
1336 if ($firstTaskId == -1)
1337 $firstTaskId= $taskId;
1338 if ($taskId ==
"ERROR")
1340 $errors[]=
"TaskIds do not have all integers";
1345 $sqlPartArray[]=
"($taskId, $index, $parentTaskId)";
1350 $transactionSQLs[]=
"update cutrackitem as ti set view_order = t.view_order, parent= t.parent from (values " . implode(
", ", $sqlPartArray) .
") as t(trackitem_id, view_order, parent) 1351 where ti.trackitem_id = t.trackitem_id";
1353 if (count($taskIds) > 0)
1355 $transactionSQLs[]=
"update cutrack set last_activity_date= now() where track_id= $issueId";
1359 if ($parentTaskId == 0)
1361 $sql=
"with ordered_trackitem as (select ti.track_id, ti.trackitem_id, ti.assigned_to, ti.parent, ti.title, ti.item_desc, row_number() over (partition by ti.parent order by ti.parent, 1362 ti.view_order, ti.trackitem_id) as number from cutrackitem ti where ti.task_status <> 2 and ti.complete_date is null and (ti.parent = $firstTaskId or ti.trackitem_id= $firstTaskId)) 1363 select t.previous_task_owner, sub.assigned_to as sassigned_to, parent.assigned_to as passigned_to, sub.title as stitle, parent.title as ptitle, sub.item_desc as sitem_desc, 1364 parent.item_desc as pitem_desc, sub.trackitem_id as strackitem_id, parent.trackitem_id as ptrackitem_id, t.assigned_to, t.issue, t.status from cutrack t 1365 left join ordered_trackitem parent on parent.parent= 0 and parent.number= 1 1366 left join ordered_trackitem sub on sub.parent= parent.trackitem_id and sub.number= 1 where t.track_id= $issueId limit 1";
1368 $results= runSelectStatement($sql, $dbh, array(
"previous_task_owner" =>
"previousTaskOwner",
"sassigned_to" =>
"subAssignedTo",
"passigned_to" =>
"parentAssignedTo",
1369 "stitle" =>
"subTitle",
"sitem_desc" =>
"subDesc",
"pitem_desc" =>
"parentDesc",
"ptitle" =>
"parentTitle",
"strackitem_id" =>
"subTaskId",
"ptrackitem_id" =>
"parentTaskId",
1370 "assigned_to" =>
"issueOwner",
"issue" =>
"issue",
"status" =>
"status"));
1371 $record= $results[
"record"][0];
1372 $errors= array_merge($errors, $results[
"error"]);
1376 $sql=
"select ti.track_id, ti.trackitem_id, ti.assigned_to as passigned_to, ti.parent, ti.title, ti.item_desc, t.assigned_to, t.issue, t.status, t.previous_task_owner from cutrack t 1377 inner join cutrackitem ti on t.track_id= ti.track_id and t.track_id= $issueId and ti.task_status <> 2 and ti.complete_date is null and ti.parent= 0 1378 order by ti.parent, ti.view_order, ti.trackitem_id limit 1";
1380 $results= runSelectStatement($sql, $dbh, array(
"previous_task_owner" =>
"previousTaskOwner",
"assigned_to" =>
"issueOwner",
"issue" =>
"issue",
"status" =>
"status",
1381 "item_desc" =>
"parentDesc",
"title" =>
"parentTitle",
"trackitem_id" =>
"parentTaskId",
"passigned_to" =>
"parentAssignedTo"));
1382 $record= $results[
"record"][0];
1383 $errors= array_merge($errors, $results[
"error"]);
1385 if ($record[
"parentTaskId"] == $parentTaskId)
1386 $sql=
"select ti.track_id, ti.trackitem_id, ti.assigned_to, ti.parent, ti.title, ti.item_desc from cutrackitem ti 1387 where ti.trackitem_id= $firstTaskId limit 1";
1389 $sql=
"select ti.track_id, ti.trackitem_id, ti.assigned_to, ti.parent, ti.title, ti.item_desc from cutrackitem ti 1390 where ti.parent= " . $record[
"parentTaskId"] .
" order by ti.parent, ti.view_order, ti.trackitem_id limit 1";
1393 $results= runSelectStatement($sql, $dbh, array(
"assigned_to" =>
"subAssignedTo",
"title" =>
"subTitle",
"item_desc" =>
"subDesc",
"trackitem_id" =>
"subTaskId"));
1395 $record= array_merge($record, $results[
"record"][0]);
1396 $errors= array_merge($errors, $results[
"error"]);
1401 $previousTaskOwner= $record[
"previousTaskOwner"];
1402 $issueOwnerId= isset($issueOwnerId) ? $issueOwnerId : $record[
"issueOwner"];
1403 $issue= $record[
"issue"];
1404 $status= $record[
"status"];
1406 if ($record[
"subTaskId"] !=
"")
1408 $nextTaskOwner= $record[
"subAssignedTo"];
1409 if ($nextTaskOwner ==
"")
1410 $nextTaskOwner= $record[
"parentAssignedTo"];
1411 if ($nextTaskOwner ==
"")
1412 $nextTaskOwner= $issueOwnerId;
1413 $title= $record[
"subTitle"];
1414 $description= $record[
"subDesc"];
1415 $taskId= $record[
"subTaskId"];
1418 else if ($record[
"parentTaskId"] !=
"")
1420 $nextTaskOwner= $record[
"parentAssignedTo"];
1421 if ($nextTaskOwner ==
"")
1422 $nextTaskOwner= $issueOwnerId;
1423 $title= $record[
"parentTitle"];
1424 $description= $record[
"parentDesc"];
1425 $taskId= $record[
"parentTaskId"];
1430 if ($hasTasks && (strtolower($nextTaskOwner) != strtolower($previousTaskOwner)))
1433 $transactionSQLs[] =
"update cutrack set previous_task_owner = '$nextTaskOwner' where track_id= $issueId";
1435 $text =
"Tasks were rearranged. $nextTaskOwner is the next task owner, not $previousTaskOwner.";
1436 $results = CreateToLine($dbh, array(trim($nextTaskOwner), trim($previousTaskOwner)));
1437 if ($results[
"status"] !==
"000") {
1438 $errors[] = $results[
"error"];
1440 $subject =
"You are the next task owner!";
1441 $taskEmails[] = array(
"to" => $results[
"data"],
"subject" => $subject,
"text" => $text,
"issue" => $issue,
"title" => $title,
1442 "description" => $description,
"issueId" => $issueId,
"taskId" => $taskId,
"completeNotes" => $completeNotes);
1449 $errors[]=
"TaskIds array is not valid";
1452 $sqls= array_merge($sqls, $transactionSQLs);
1453 if (count($errors) == 0)
1455 $results= runExecStatement(implode(
";", $transactionSQLs), $dbh);
1456 $errors= array_merge($errors, $results[
"error"]);
1457 if (count($errors) == 0)
1459 foreach($taskEmails as $taskEmail)
1461 createTaskEmail($taskEmail[
"to"], $taskEmail[
"subject"], $taskEmail[
"text"], $taskEmail[
"issue"], $taskEmail[
"title"], $taskEmail[
"description"], $cuName, $cu,
1462 $taskEmail[
"issueId"], $taskEmail[
"taskId"],
"", $taskEmail[
"completeNotes"]);
1464 foreach($issueEmails as $issueEmail)
1466 createIssueEmail($issueEmail[
"to"], $issueEmail[
"subject"], $issueEmail[
"text"], $issueEmail[
"issue"], $issueEmail[
"status"], $cuName, $cu, $issueEmail[
"issueId"],
1467 "", $issueEmail[
"completeNotes"]);
1472 return array(
"error" => $errors,
"sql" => $sqls);
1476 function modifyTaskComment($dbh, $staffId, $isAdd)
1478 $parameters= array();
1479 $import= array(
"text" =>
"string");
1482 $import[
"taskId"]=
"string";
1483 $import[
"issueId"]=
"string";
1484 $import[
"cu"]=
"string";
1488 $import[
"commentId"]=
"string";
1490 dms_import_v2($parameters,
"BOTTOM_LEVEL", $import);
1492 $text= $parameters[
"BOTTOM_LEVEL"][
"text"];
1493 $errors= cleanValuesForDatabase($parameters[
"BOTTOM_LEVEL"],
1494 array(
"taskId" => array(
"required" =>
true,
"type" =>
"int"),
1495 "issueId" => array(
"required" =>
true,
"type" =>
"int"),
1496 "text" => array(
"required" =>
false,
"type" =>
"string"),
1497 "cu" => array(
"required" =>
true,
"type" =>
"string",
"maxlength" => 10),
1498 "commentId" => array(
"required" =>
true,
"type" =>
"int"),
1499 "isFirstTask" => array(
"required" =>
false,
"type" =>
"boolean")));
1501 $taskId= $parameters[
"BOTTOM_LEVEL"][
"taskId"];
1502 $issueId= $parameters[
"BOTTOM_LEVEL"][
"issueId"];
1503 $textClean= $parameters[
"BOTTOM_LEVEL"][
"text"];
1504 $cu= strtolower($parameters[
"BOTTOM_LEVEL"][
"cu"]);
1505 $commentId= isset($parameters[
"BOTTOM_LEVEL"][
"commentId"]) ? intval($parameters[
"BOTTOM_LEVEL"][
"commentId"]) : 0;
1506 $isFirstTask= isset($parameters[
"BOTTOM_LEVEL"][
"isFirstTask"]) ? ($parameters[
"BOTTOM_LEVEL"][
"isFirstTask"] ==
"Y") :
false;
1508 $record= array(
"commentId" => $commentId,
"author" => $staffId,
"text" => $text,
"trackItemId" => $taskId);
1510 $textClean= $textClean ==
"" ?
"null" :
"'$textClean'";
1511 $cu= $cu ==
"" ?
"null" :
"'$cu'";
1513 $transactionSQLs= array();
1517 $sql=
"select nextval('cuinfo_notes_messageid_seq'::text::regclass) as next";
1520 $results= runSelectStatement($sql, $dbh, array(
"next" =>
"next"));
1521 $errors= array_merge($errors, $results[
"error"]);
1522 $commentId= intval($results[
"record"][0][
"next"]);
1523 $record[
"commentId"]= $commentId;
1525 $transactionSQLs[]=
"insert into cuinfo_notes (messageid, trackitem_id, track_id, messagetext, cu, author, createddate, activitydate) values ($commentId, $taskId, $issueId, $textClean, $cu, 1526 '$staffId', now(), now())";
1530 $transactionSQLs[]=
"update cuinfo_notes set messagetext=$textClean, activitydate=now() where messageid=$commentId";
1533 $transactionSQLs[]=
"update cutrack set last_activity_date= now() where track_id= $issueId";
1535 $sqls= array_merge($sqls, $transactionSQLs);
1537 if (count($errors) == 0)
1539 $results= runExecStatement(implode(
";", $transactionSQLs), $dbh);
1540 $errors= array_merge($errors, $results[
"error"]);
1543 return array(
"error" => $errors,
"sql" => $sqls,
"record" => array($record));
1547 function updateBilling($dbh, $issueId, &$transactionSQLs)
1549 $nextMonth=
new DateTime();
1550 $m = $nextMonth->format(
'm');
1551 $Y = $nextMonth->format(
'Y');
1552 $nextMonth->setDate($Y, $m, 1);
1553 $thisMonthDate= $nextMonth->format(
"Y-m-d");
1554 $nextMonth->setDate($Y, $m+1, 1);
1555 $nextMonthDate= $nextMonth->format(
"Y-m-d");
1557 $transactionSQLs[]=
"update cubillfeaturedetail set billing_status= case when billing_status = 0 then 3 else 2 end, start_date= '$nextMonthDate', end_date= '$nextMonthDate', 1558 workflow_completed= 'Y' where id in (select billing_feature_id from cutrack where track_id= $issueId) and workflow_completed= 'N'";
1562 function promoteTask($dbh, $staffId)
1564 $parameters= array();
1565 dms_import_v2($parameters,
"BOTTOM_LEVEL", array(
"taskId" =>
"string",
"parentTaskId" =>
"string",
"cu" =>
"string",
"cuName" =>
"string",
"trackId" =>
"string"));
1567 $cu= strtoupper($parameters[
"BOTTOM_LEVEL"][
"cu"]);
1568 $cuName= $parameters[
"BOTTOM_LEVEL"][
"cuName"];
1570 $errors= cleanValuesForDatabase($parameters[
"BOTTOM_LEVEL"],
1571 array(
"taskId" => array(
"required" =>
true,
"type" =>
"int"),
1572 "parentTaskId" => array(
"required" =>
true,
"type" =>
"int"),
1573 "cu" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 12),
1574 "cuName" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 40),
1575 "trackId" => array(
"type" =>
"int",
"required" =>
true)));
1577 $taskId= $parameters[
"BOTTOM_LEVEL"][
"taskId"];
1578 $parentTaskId= $parameters[
"BOTTOM_LEVEL"][
"parentTaskId"];
1579 $issueId= intval($parameters[
"BOTTOM_LEVEL"][
"trackId"]);
1581 $transactionSQLs= array();
1583 $taskEmails= array();
1584 $issueEmails= array();
1586 $transactionSQLs[]=
"update cutrackitem set view_order= temp.position, parent= 0 1587 from (select i.trackitem_id, row_number() over(order by i.trackitem_id in ($parentTaskId,$taskId) desc, i.view_order, i.trackitem_id)+coalesce(iparent.view_order,0) as position 1588 from cutrackitem i inner join cutrackitem iparent on i.track_id= iparent.track_id and i.track_id= $issueId and iparent.trackitem_id= $parentTaskId 1589 where i.trackitem_id= $taskId or ( coalesce(i.view_order,0) >= coalesce(iparent.view_order,0) and i.parent= 0)) temp 1590 where cutrackitem.trackitem_id= temp.trackitem_id";
1592 $transactionSQLs[]=
"update cutrack set last_activity_date= now() where track_id= $issueId";
1595 notifyNextTaskOwner($dbh, $issueId,
null, $staffId,
"promoted",
null, $errors, $transactionSQLs, $taskEmails, $issueEmails);
1597 $sqls= array_merge($sqls, $transactionSQLs);
1598 if (count($errors) == 0)
1600 $results= runExecStatement(implode(
";", $transactionSQLs), $dbh);
1601 $errors= array_merge($errors, $results[
"error"]);
1602 if (count($errors) == 0)
1604 foreach($taskEmails as $taskEmail)
1606 createTaskEmail($taskEmail[
"to"], $taskEmail[
"subject"], $taskEmail[
"text"], $taskEmail[
"issue"], $taskEmail[
"title"], $taskEmail[
"description"], $cuName, $cu,
1607 $taskEmail[
"issueId"], $taskEmail[
"taskId"],
"", $taskEmail[
"completeNotes"]);
1609 foreach($issueEmails as $issueEmail)
1611 createIssueEmail($issueEmail[
"to"], $issueEmail[
"subject"], $issueEmail[
"text"], $issueEmail[
"issue"], $issueEmail[
"status"], $cuName, $cu, $issueEmail[
"issueId"],
1612 "", $issueEmail[
"completeNotes"]);
1617 return array(
"sql" => $sqls,
"error" => $errors);
1620 function addIssueFromTemplate($dbh, $staffId)
1623 $parameters= array();
1624 dms_import_v2($parameters,
"BOTTOM_LEVEL", array(
"templateId" =>
"string",
"cu" =>
"string",
"cuName" =>
"string"));
1626 $cu= strtolower($parameters[
"BOTTOM_LEVEL"][
"cu"]);
1627 $cuName= $parameters[
"BOTTOM_LEVEL"][
"cuName"];
1629 $errors= cleanValuesForDatabase($parameters[
"BOTTOM_LEVEL"],
1630 array(
"templateId" => array(
"required" =>
true,
"type" =>
"int"),
1631 "cu" => array(
"required" =>
true,
"type" =>
"string",
"maxlength" => 12),
1632 "cuName" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 40)));
1633 $templateId= $parameters[
"BOTTOM_LEVEL"][
"templateId"];
1635 $transactionSQLs= array();
1636 $taskEmails= array();
1638 $findIssueSQL=
"select i.issue_id, i.code, i.owner, ii.item_id, ii.title, ii.item_desc, ii.view_order, ii.owner as task_owner, ii.parent, ii.sales_item_id 1639 from cuissues i left join cuissuesitem ii on i.issue_id = ii.issue_id where i.issue_id = '$templateId' order by i.issue_id, ii.parent, ii.view_order, ii.item_id";
1640 $results= runSelectStatement($findIssueSQL, $dbh, array(
"issue_id" =>
"issueId",
"code" =>
"issueTitle",
"owner" =>
"issueOwner",
"item_id" =>
"taskId",
"title" =>
"taskTitle",
1641 "item_desc" =>
"taskDescription",
"view_order" =>
"taskViewOrder",
"task_owner" =>
"taskOwner",
"parent" =>
"taskParent",
"sales_item_id" =>
"salesItemId"));
1643 $getNextIdSQL=
"select nextval('cutrackitem_trackitem_id_seq'::text::regclass) as next";
1644 $nextResults= runSelectStatement($getNextIdSQL, $dbh, array(
"next" =>
"next"));
1645 $errors= array_merge($errors, $results[
"error"], $nextResults[
"error"]);
1646 array_push($sqls, $findIssueSQL, $getNextIdSQL);
1648 $nextTaskId= intval($nextResults[
"record"][0][
"next"]);
1650 $insertIssueSQL=
"insert into cutrack (track_id, issue, assigned_to, previous_task_owner, user_name, status, target_date_type, entry_date, last_activity_date, issue_id)";
1651 $insertTasksSQL=
"insert into cutrackitem (trackitem_id, track_id, title, item_desc, view_order, parent, assigned_to, issue_item_id, billing_item_id)";
1654 $taskSQLPartArray= array();
1655 $subTaskArray= array();
1656 $parentArray= array();
1659 $templateIssueId=
"";
1661 $parentTaskId= $nextTaskId;
1663 $previousTaskOwner=
"";
1664 $firstParentTask=
null;
1665 $firstSubTask=
null;
1666 $firstParentTaskId=
"";
1667 $taskIdMap= array();
1668 foreach($results[
"record"] as $record)
1672 $issueName= $record[
"issueTitle"];
1673 $issue= prepSave($record[
"issueTitle"], 90);
1674 $issueOwner= trim(strval($record[
"issueOwner"])) !=
"" ? prepSave($record[
"issueOwner"], 30) : prepSave($staffId, 30);
1675 $templateIssueId= $record[
"issueId"];
1677 $sql=
"select nextval('cutrack_track_id_seq'::text::regclass) as next";
1678 $results= runSelectStatement($sql, $dbh, array(
"next" =>
"next"));
1679 $errors= array_merge($errors, $results[
"error"]);
1681 $issueId= intval($results[
"record"][0][
"next"]);
1682 $taskOwner = $record[
"taskOwner"];
1684 $insertIssueSQL.=
" values ($issueId, '$issue', '$issueOwner', '$taskOwner', '$cu', 'Active', 'TBD', now(), now(), $templateId)";
1685 $transactionSQLs[]= $insertIssueSQL;
1687 $previousTaskOwner= $record[
"issueOwner"];
1691 $taskId= $record[
"taskId"];
1693 if($taskId !=
"" && $templateIssueId == $record[
"issueId"])
1695 $title= prepSave($record[
"taskTitle"], 80);
1696 $description= prepSave($record[
"taskDescription"]);
1697 $viewOrder= $record[
"taskViewOrder"];
1698 $owner= prepSave($record[
"taskOwner"], 12);
1699 $parent= $record[
"taskParent"];
1700 $taskTemplateId= $record[
"taskId"];
1701 $salesItemId= intval($record[
"salesItemId"]);
1706 if (!isset($firstParentTask))
1708 $firstParentTask= $record;
1710 $taskIdMap[$taskTemplateId]= $parentTaskId;
1711 $taskSQLPartArray[]=
"($parentTaskId, $issueId, '$title', '$description', $viewOrder, 0, '$owner', $taskTemplateId, $salesItemId)";
1712 $parentArray[$taskTemplateId]= $index++;
1717 if (!isset($subTaskArray[$parent]))
1718 $subTaskArray[$parent]= array();
1719 $subTaskArray[$parent][]= $record;
1725 $subTaskId= $parentTaskId;
1728 $transactionSQLs[]=
"$insertTasksSQL values " . implode(
", ", $taskSQLPartArray);
1730 $taskSQLPartArray= array();
1732 foreach($subTaskArray as $parentId => $detailRecords)
1734 $parentTaskId= $nextTaskId + $parentArray[$parentId];
1735 foreach($detailRecords as $record)
1737 $title= prepSave($record[
"taskTitle"], 80);
1738 $description= prepSave($record[
"taskDescription"]);
1739 $viewOrder= $record[
"taskViewOrder"];
1740 $owner= prepSave($record[
"taskOwner"], 12);
1741 $taskTemplateId= $record[
"taskId"];
1742 $taskIdMap[$taskTemplateId]= $subTaskId;
1743 $salesItemId= intval($record[
"salesItemId"]);
1745 $taskSQLPartArray[]=
"($subTaskId, $issueId, '$title', '$description', $viewOrder, $parentTaskId, '$owner', $taskTemplateId, $salesItemId)";
1750 if (count($taskSQLPartArray) > 0)
1752 $transactionSQLs[]=
"$insertTasksSQL values " . implode(
", ", $taskSQLPartArray);
1755 $transactionSQLs[]=
"select setval('cutrackitem_trackitem_id_seq'::text::regclass, $subTaskId, false)";
1758 $issueEmail= array();
1759 $taskEmail= array();
1762 if (isset($firstParentTask))
1764 $firstSubTask=
null;
1765 if (!empty($subTaskArray) && HCU_array_key_exists($firstParentTask[
"taskId"], $subTaskArray)) {
1766 $firstSubTask= $subTaskArray[$firstParentTask[
"taskId"]][0];
1769 if (isset($firstSubTask))
1771 $title= $firstSubTask[
"taskTitle"];
1772 $description= $firstSubTask[
"taskDescription"];
1773 $taskId= $taskIdMap[$firstSubTask[
"taskId"]];
1774 $taskOwner= $firstSubTask[
"taskOwner"] ==
"" ? ($firstParentTask[
"taskOwner"] ==
"" ? $issueOwner : $firstParentTask[
"taskOwner"]) : $firstSubTask[
"taskOwner"];
1778 $title= $firstParentTask[
"taskTitle"];
1779 $description= $firstParentTask[
"taskDescription"];
1780 $taskId= $taskIdMap[$firstParentTask[
"taskId"]];
1781 $taskOwner= $firstParentTask[
"taskOwner"] ==
"" ? $issueOwner : $firstParentTask[
"taskOwner"];
1784 $text =
"Job has been created. You are the first task owner.";
1785 $results = CreateToLine($dbh, array(trim($taskOwner)));
1786 if ($results[
"status"] !==
"000") {
1787 $errors[] = $results[
"error"];
1789 $subject =
"You are the next task owner!";
1790 $taskEmails[] = array(
"to" => $results[
"data"],
"subject" => $subject,
"text" => $text,
"issue" => $issue,
"title" => $title,
1791 "description" => $description,
"issueId" => $issueId,
"taskId" => $taskId);
1793 $transactionSQLs[] =
"update cutrack set previous_task_owner = '$taskOwner' where track_id = $issueId";
1797 $sqls= array_merge($sqls, $transactionSQLs);
1799 if (count($errors) == 0)
1801 $results= runExecStatement(implode(
";", $transactionSQLs) .
";", $dbh);
1802 $errors= array_merge($errors, $results[
"error"]);
1803 if (count($errors) == 0)
1805 $results = createToLine($dbh, array(trim($issueOwner)));
1806 if ($results[
"status"] !==
"000") {
1807 $errors[] = $results[
"error"];
1809 $subject =
"Job has been created from template!";
1810 $text =
"Workflow is set up which is assigned to you.";
1811 $text2 =
"Please mark non-relevant tasks to N/A and activate issue so that it can be worked.";
1812 CreateIssueEmail($results[
"data"], $subject, $text, $issueName,
"Active", $cuName, $cu, $issueId, $text2);
1814 foreach($taskEmails as $taskEmail) {
1815 CreateTaskEmail($taskEmail[
"to"], $taskEmail[
"subject"], $taskEmail[
"text"], $issueName, $taskEmail[
"title"], $taskEmail[
"description"],
1816 $cuName, $cu, $issueId, $taskEmail[
"taskId"]);
1821 return array(
"sql" => $sqls,
"error" => $errors,
"trackId" => $issueId);
1824 function deleteTaskComment($dbh)
1827 $parameters= array();
1828 dms_import_v2($parameters,
"BOTTOM_LEVEL", array(
"commentId" =>
"string"));
1830 $transactionSQLs= array();
1832 $errors= cleanValuesForDatabase($parameters[
"BOTTOM_LEVEL"],
1833 array(
"commentId" => array(
"required" =>
true,
"type" =>
"int")));
1835 $commentId= $parameters[
"BOTTOM_LEVEL"][
"commentId"];
1837 $transactionSQLs[]=
"delete from cuinfo_notes where messageid= $commentId";
1838 $transactionSQLs[]=
"update cutrack set last_activity_date= now() where track_id= $issueId";
1840 if (count($errors) == 0)
1842 $results= runExecStatement(implode(
";", $transactionSQLs) .
";", $dbh);
1843 $errors= array_merge($errors, $results[
"error"]);
1845 return array(
"sql" => $transactionSQLs,
"error" => $errors,
"operation" =>
"delete");
1848 function pullInTaskTemplates($dbh)
1850 $parameters= array();
1851 dms_import_v2($parameters,
"BOTTOM_LEVEL", array(
"taskTemplateIds" =>
"string",
"trackId" =>
"string",
"taskLength" =>
"string",
"issueId" =>
"string"));
1853 $errors= cleanValuesForDatabase($parameters[
"BOTTOM_LEVEL"],
1854 array(
"trackId" => array(
"required" =>
true,
"type" =>
"int"),
1855 "taskLength" => array(
"required" =>
true,
"type" =>
"int"),
1856 "issueId" => array(
"required" =>
true,
"type" =>
"int")));
1858 $taskTemplateIdsEncoded= $parameters[
"BOTTOM_LEVEL"][
"taskTemplateIds"];
1859 $trackId= $parameters[
"BOTTOM_LEVEL"][
"trackId"];
1860 $taskLength= $parameters[
"BOTTOM_LEVEL"][
"taskLength"];
1861 $issueId= $parameters[
"BOTTOM_LEVEL"][
"issueId"];
1863 $transactionSQLs= array();
1865 if (trim($taskTemplateIdsEncoded) ==
"")
1866 $errors[]=
"TaskTemplateIds are required";
1869 $taskTemplateIds= json_decode($taskTemplateIdsEncoded,
true);
1870 if (is_array($taskTemplateIds))
1872 foreach($taskTemplateIds as $templateId)
1874 $templateId= cleanInteger($templateId);
1875 if ($templateId ==
"ERROR")
1877 $errors[]=
"One or more TaskTemplateIds is not an integer.";
1883 $errors[]=
"TaskTemplateIds not an array";
1886 $findSql=
"select ii.item_id, ii.title, ii.item_desc, ii.view_order, ii.owner as task_owner, ii.parent, i.owner as job_owner, ii.sales_item_id from cuissuesitem ii 1887 inner join cuissues i on ii.issue_id = i.issue_id where ii.item_id in (" . implode(
",", $taskTemplateIds) .
") and ii.issue_id = $issueId";
1889 $getNextIdSQL=
"select nextval('cutrackitem_trackitem_id_seq'::text::regclass) as next";
1890 $nextResults= runSelectStatement($getNextIdSQL, $dbh, array(
"next" =>
"next"));
1891 $errors= array_merge($errors, $nextResults[
"error"]);
1892 $sqls= array($findSql, $getNextIdSQL);
1893 $nextTaskId= intval($nextResults[
"record"][0][
"next"]);
1894 $parentTaskId= $nextTaskId;
1895 $subTaskArray= array();
1897 if (count($taskTemplateIds) > 0)
1899 $results= runSelectStatement($findSql, $dbh, array(
"item_id" =>
"taskId",
"title" =>
"taskTitle",
"item_desc" =>
"taskDescription",
"view_order" =>
"taskViewOrder",
1900 "task_owner" =>
"taskOwner",
"parent" =>
"taskParent",
"job_owner" =>
"jobOwner",
"sales_item_id" =>
"billingItemId"));
1901 $errors= $results[
"error"];
1903 $insertTasksSQL=
"insert into cutrackitem (trackitem_id, track_id, title, item_desc, view_order, parent, assigned_to, issue_item_id, billing_item_id)";
1904 $taskSQLPartArray= array();
1907 foreach($results[
"record"] as $record)
1909 if (intval($record[
"billingItemId"]) != 0)
1910 $taskList[]=
"(" . intval($record[
"taskId"]) .
", " . intval($record[
"billingItemId"]) .
")";
1913 if (count($taskList) != 0)
1915 $sql=
"select t.task_id, fd.id from cutrack ct inner join cubillfeaturedetail bfd on ct.billing_feature_id = bfd.id and ct.track_id= $trackId 1916 inner join cubillsalesorderdetail sod on bfd.sales_order_detail_id = sod.id inner join cubillfeaturedetail fd on sod.id = fd.sales_order_detail_id 1917 inner join (values " . implode(
", ", $taskList) .
") as t (task_id, sales_item_id) on fd.sales_item_id= t.sales_item_id";
1918 $tempResults= runSelectStatementMap($sql, $dbh);
1920 $errors= array_merge($errors, $tempResults[
"error"]);
1921 $map=$tempResults[
"record"];
1923 for($i=0, $count=count($results[
"record"]); $i != $count; $i++)
1925 $billingItemId= $map[$results[
"record"][$i][
"taskId"]];
1926 if (isset($billingItemId))
1927 $results[
"record"][$i][
"billingItemId"]= $billingItemId;
1932 foreach($results[
"record"] as $record)
1934 $title= prepSave($record[
"taskTitle"], 80);
1935 $description= prepSave($record[
"taskDescription"]);
1936 $viewOrder= $taskLength + intval($record[
"taskViewOrder"]);
1937 $owner= prepSave($record[
"taskOwner"], 12);
1938 $parent= $record[
"taskParent"];
1939 $taskTemplateId= $record[
"taskId"];
1940 $billingItemId= $record[
"billingItemId"];
1944 $taskSQLPartArray[]=
"($parentTaskId, $trackId, '$title', '$description', $viewOrder, 0, '$owner', $taskTemplateId, $billingItemId)";
1945 $parentArray[$taskTemplateId]= $index++;
1950 if (!isset($subTaskArray[$parent]))
1951 $subTaskArray[$parent]= array();
1952 $subTaskArray[$parent][]= $record;
1957 $subTaskId= $parentTaskId;
1960 $transactionSQLs[]=
"$insertTasksSQL values " . implode(
", ", $taskSQLPartArray);
1962 $taskSQLPartArray= array();
1964 foreach($subTaskArray as $parentId => $detailRecords)
1966 $parentTaskId= $nextTaskId + $parentArray[$parentId];
1968 foreach($detailRecords as $record)
1970 $title= prepSave($record[
"taskTitle"], 80);
1971 $description= prepSave($record[
"taskDescription"]);
1972 $viewOrder= $record[
"taskViewOrder"];
1973 $owner= prepSave($record[
"taskOwner"], 12);
1974 $taskTemplateId= $record[
"taskId"];
1975 $billingItemId= $record[
"billingItemId"];
1977 $taskSQLPartArray[]=
"($subTaskId, $trackId, '$title', '$description', $viewOrder, $parentTaskId, '$owner', $taskTemplateId, $billingItemId)";
1982 if (count($taskSQLPartArray) > 0)
1984 $transactionSQLs[]=
"$insertTasksSQL values " . implode(
", ", $taskSQLPartArray);
1987 $transactionSQLs[]=
"select setval('cutrackitem_trackitem_id_seq'::text::regclass, $subTaskId, false)";
1990 $transactionSQLs[]=
"update cutrack set last_activity_date= now() where track_id= $trackId";
1993 $sqls= array_merge($sqls, $transactionSQLs);
1994 if (count($errors) == 0)
1996 $results= runExecStatement(implode(
";", $transactionSQLs) .
";", $dbh);
1997 $errors= array_merge($errors, $results[
"error"]);
2001 $requerySQL=
"select i.trackitem_id, i.title, i.item_desc, i.complete_date, i.task_status, i.parent, i.assigned_to, i.last_status_changed, i.view_order as position, i.issue_item_id 2002 from cutrackitem i where i.track_id= $trackId and i.issue_item_id in (" . implode(
",", $taskTemplateIds) .
") 2003 order by i.parent, i.task_status, i.view_order, i.trackitem_id";
2004 $sqls[]= $requerySQL;
2005 if (count($taskTemplateIds) > 0)
2007 $results= runSelectStatement($requerySQL, $dbh, array(
"trackitem_id" =>
"taskId",
"title" =>
"title",
"item_desc" =>
"description",
"complete_date" =>
"completedOn",
"position" =>
"position",
2008 "task_status" =>
"statusId",
"parent" =>
"parentTaskId",
"assigned_to" =>
"ownerId",
"last_status_changed" =>
"statusChangedDate",
2009 "issue_item_id" =>
"taskTemplateId"));
2010 $errors= array_merge($errors, $results[
"error"]);
2011 $records= $results[
"record"];
2014 return array(
"sql" => $sqls,
"error" => $errors,
"record" => $records);
2017 function setReportCookie($pEnv)
2019 $parameters= array();
2020 dms_import_v2($parameters,
"BOTTOM_LEVEL", array(
"sort" =>
"string",
"filter" =>
"string",
"showDeleted" =>
"string",
"showCompleted" =>
"string"));
2021 $sort= $parameters[
"BOTTOM_LEVEL"][
"sort"];
2022 $filter= $parameters[
"BOTTOM_LEVEL"][
"filter"];
2023 $showDeleted= $parameters[
"BOTTOM_LEVEL"][
"showDeleted"] ==
"Y" ?
"Y" :
"N";
2024 $showCompleted= $parameters[
"BOTTOM_LEVEL"][
"showCompleted"] ==
"Y" ?
"Y" :
"N";
2027 $sortUnpacked= json_decode($sort,
true);
2028 $filterUnpacked= json_decode($filter,
true);
2029 if ($sort !=
"" && !is_array($sortUnpacked))
2030 $errors[]=
"Sort is invalid";
2031 if ($filter !=
"" && !is_array($filterUnpacked))
2032 $errors[]=
"Filter is invalid";
2034 $expiresInDay= time()+86400;
2035 $expiresInYear= time()+86400*365;
2037 HCU_setcookie_env($pEnv,
"Job_View",
"sort=" . urlencode($sort) .
"&filter=" . urlencode($filter) .
"&showDeleted=$showDeleted&showCompleted=$showCompleted", $expiresInDay);
2038 return array(
"error" => $errors,
"sql" => array());
2041 function clearReportCookie($pEnv)
2043 if (isset($_COOKIE[
"Job_View"]))
2045 unset($_COOKIE[
"Job_View"]);
2046 HCU_setcookie_env($pEnv,
"Job_View",
"", time() - 3600);
2048 return array(
"error" => array(),
"sql" => array());