Odyssey
cuissuesmntc.prg
1 <?php
2  // ** Include these scripts, mostly to ensure that the Monitor security is maintained
3  $monLibrary = dirname(__FILE__) . "/../library";
4  $billingLibrary = dirname(__FILE__) . "/../../billing/library";
5  require_once("$monLibrary/cu_top.i");
6  require_once("$monLibrary/ck_hticket.i");
7 
8  require_once("$billingLibrary/configuration.i"); // For using only "triggered" sales items.
9 
10  if (!CheckPerm($link, $Hu, basename($_SERVER['SCRIPT_NAME']), $_SERVER['REMOTE_ADDR'])) {
11  // ** Permissions failed
12  // ** redirect to new page
13  header("Location: /hcuadm/hcu_noperm.prg");
14  exit;
15  }
16 
17 $dms_ok=array('act'=>'string','addRows'=>'string','btn_act'=>'string',
18 'btnAddRows'=>'string','btn_stop'=>'string','direction_to_move'=>'string',
19 'iid'=>'string','iss_code'=>'string','iss_id'=>'string',
20 'iss_prod'=>'string','iss_owner'=>'string','item_del_'=>'prefix_s','item_desc_'=>'prefix_s',
21 'item_id_'=>'prefix_s','item_title_'=>'prefix_s','item_owner_'=>'prefix_s','item_parent_'=>'prefix_s',
22 'row_to_move'=>'string','saveForm'=>'string','total_rows'=>'string', 'sales_item_id_'=>'prefix_s');
23 
24 dms_import($dms_ok);
25 
26 $iss_id = isset($iss_id) ? $iss_id : 0;
27 $iss_code = isset($iss_code) ? $iss_code : "";
28 $iss_prod = isset($iss_prod) ? $iss_prod : "";
29 $iss_owner = isset($iss_owner) ? $iss_owner : "";
30  $form_err = "";
31  $form_msg = "";
32 
33  if (!isset($act)) {
34  $act = "2";
35  } else {
36  if ($act == 1 && isset($saveForm)) {
37  $act = 3;
38  } elseif ($act == 4 && intval($iid) > 0 && isset($btn_act)) {
39  $act = 6; // For DELETE Only
40  } elseif ($act == 4 && isset($btn_stop)) {
41  $act = 2;
42  }
43  }
44 
45  // Before showing form -- do other functions
46  // Act - 3: Saving the form
47  // Act - 6: Deleting the form
48 
49  if ($act == 3) {
50  /* VALIDATE THE INFORMATION - whether it's been saved before or NOT
51  After validation fails it will send the information back to the edit form
52  So it looks like it did before, the fail information will be at the bottom of the
53  screen.
54 
55  */
56 
57  // Don't be too strict on the Code being the same as any other
58  // Make sure a code is entered
59  if (strlen(trim($iss_code)) == 0) {
60  $form_err .= "<li>You must enter a code to be saved.<br>";
61  }
62  // Make sure a default owner is entered
63  if (strlen(trim($iss_owner)) == 0) {
64  $form_err .= "<li>You must enter a default owner to be saved.<br>";
65  }
66  // SAVE any detail items
67  for ($row_idx = 1; $row_idx <= $total_rows; $row_idx++) {
68  // Check for the existance of the item ID if found then REQUIRE title and description
69  $item_id = isset(${'item_id_' . $row_idx}) ? intval(${'item_id_' . $row_idx}) : 0;
70  $item_title = isset(${'item_title_' . $row_idx}) ? trim(${'item_title_' . $row_idx}) : "";
71  $item_desc = isset(${'item_desc_' . $row_idx}) ? trim(${'item_desc_' . $row_idx}) : "";
72  $item_owner = isset(${'item_owner_' . $row_idx}) ? trim(${'item_owner_' . $row_idx}) : "";
73  $item_del = isset(${'item_del_' . $row_idx}) ? ${'item_del_' . $row_idx} : "";
74  $sales_item_id= isset(${'sales_item_id_' . $row_idx}) ? intval(${'sales_item_id_' . $row_idx}) : 0;
75 
76  $req_fields = false;
77 
78  if ($item_del != "Y") {
79  if ($item_id > 0) {
80  // UPDATING ITEM
81  $req_fields = true;
82  } else {
83  // INSERTING ITEM
84  if (strlen($item_title) > 0 || strlen($item_desc) > 0 ) {
85  $req_fields = true;
86  }
87  }
88  }
89  if ($req_fields) {
90  if (strlen($item_title) == 0) {
91  $form_err .= "<li>Row $row_idx does not contain an item title.<br>";
92  }
93  if (strlen($item_desc) == 0) {
94  $form_err .= "<li>Row $row_idx does not contain an item description.<br>";
95  }
96  }
97  }
98  if (strlen($form_err) == 0) {
99  // Everything was validated, we now need to save the information, either insert for new or update for edited.
100 
101  if (isset($iss_id) && intval($iss_id) > 0 ) {
102  $save_issue_id = intval($iss_id);
103  // UPDATE the information into the table
104  $sql = "UPDATE cuissues
105  SET code = '" . prep_save($iss_code, 80) . "',
106  gen_for_product = '" . prep_save($iss_prod, 10) . "',
107  owner = '" . prep_save($iss_owner, 12) . "'
108  WHERE issue_id = '$save_issue_id'; ";
109  } else {
110  // First retrieve the next Issue ID value from the sequence
111  $sql = "SELECT nextval('cuissues_issue_id_seq');";
112  if ($seq_rs = db_query($sql, $link)) {
113 
114  list($save_issue_id) = db_fetch_array($seq_rs, 0);
115  $sql = "INSERT INTO cuissues
116  (issue_id, code, gen_for_product, owner)
117  VALUES
118  ('$save_issue_id', '" . prep_save($iss_code, 80) . "', '" . prep_save($iss_prod, 10) . "', '" . prep_save($iss_owner, 12) . "'); ";
119  } else {
120  trigger_error("SQL Failure: $sql :: " . pg_errormessage($link), E_USER_NOTICE);
121  // UNABLE to retrieve the next value in the Issue id sequence
122  $form_err = "Unable to save the CU Job Template at this time.<br><br>Please try again.";
123  $act = 1;
124  }
125  db_free_result($seq_rs);
126  }
127 
128  // Only advance if we successfully retrieved an issue id
129  if (isset($save_issue_id) && $save_issue_id > 0) {
130  for ($row_idx = 1; $row_idx <= $total_rows; $row_idx++) {
131  // Check for the existance of the item ID if found then REQUIRE title and description
132  $item_id = isset(${'item_id_' . $row_idx}) ? intval(${'item_id_' . $row_idx}) : 0;
133  $item_parent = isset(${'item_parent_' . $row_idx}) ? intval(${'item_parent_' . $row_idx}) : "";
134  $item_title = isset(${'item_title_' . $row_idx}) ? prep_save(${'item_title_' . $row_idx}, 50) : "";
135  $item_desc = isset(${'item_desc_' . $row_idx}) ? prep_save(${'item_desc_' . $row_idx}) : "";
136  $item_owner = isset(${'item_owner_' . $row_idx}) ? prep_save(${'item_owner_' . $row_idx}) : "";
137  $item_del = isset(${'item_del_' . $row_idx}) ? ${'item_del_' . $row_idx} : "";
138  $sales_item_id = isset(${'sales_item_id_' . $row_idx}) ? intval(${'sales_item_id_' . $row_idx}) : 0;
139 
140  // Now SAVE the information -- if the item_id is set then UPDATE
141  // Otherwise INSERT
142  if ($item_del == "Y" && $item_id > 0) {
143  $sql .= "DELETE FROM cuissuesitem WHERE item_id = $item_id; ";
144  } elseif ($item_del != "Y" && strlen($item_title) > 0) {
145  if ($item_id > 0) {
146  // UPDATE item
147  $sql .= "UPDATE cuissuesitem
148  SET title = '$item_title',
149  item_desc = '$item_desc',
150  view_order = '$row_idx',
151  owner = '$item_owner',
152  parent = $item_parent,
153  sales_item_id= $sales_item_id
154  WHERE item_id = $item_id; ";
155  } else {
156  // INSERT ITEM
157  $sql .= "INSERT INTO cuissuesitem
158  (issue_id, title, item_desc, view_order, owner, parent, sales_item_id)
159  VALUES
160  ($save_issue_id, '$item_title', '$item_desc', '$row_idx', '$item_owner', $item_parent, $sales_item_id); ";
161  }
162  }
163  }
164 
165 
166  // Now pass the query to the Database
167  if (!($db_result=db_query($sql, $link))) {
168  trigger_error("SQL Failure: $sql ::" . pg_errormessage($link) , E_USER_NOTICE);
169  $form_err = "Unable to save the CU Job Template at this time.<br><br>Please try again.";
170  $act = 1; // After FAILED saving -- set this to 1 so we can view the form
171  } else {
172  $form_msg = "The code '{$iss_code}' was saved successfully.";
173  $act = 2; // After SUCCESSFUL saving -- set this to 2 to view ALL the codes
174  }
175  }
176  } else {
177  // Errors Found -- force back to the edit form
178  $act = 1;
179  }
180  } elseif ($act == 6) {
181 
182  if (intval($iid) > 0) {
183  $sql = "DELETE FROM cuissues WHERE issue_id = '" . intval($iid) . "'; ";
184  $sql .= "DELETE FROM cuissuesitem WHERE issue_id = '" . intval($iid) . "'; ";
185  if ($del_rs = db_query($sql, $link)) {
186  $form_msg = "The record was successfully deleted.";
187  } else {
188  $form_err = "Something happened, and the record was NOT deleted. Sorry for any inconvenience.";
189  }
190  $act = 2;
191  }
192  }
193 
194 
195  switch ($act):
196  case "1": // Edit Cu Vendors
197  $num_rows = 0;
198  $load_issue_id = 0;
199  if (isset($iss_id)) {
200  $formmode = "Edit";
201  $load_issue_id = intval($iss_id);
202 
203  // Connect to the database - get the team information from the database
204  $sql = "SELECT *
205  FROM cuissues
206  WHERE issue_id= '{$iss_id}'";
207  $result = db_query($sql, $link);
208  // Now fetch the row
209  $cuissues_row = db_fetch_object($result);
210  $num_rows = db_num_rows($result);
211  } else {
212  $formmode = "Add";
213  }
214  cu_header("$formmode CU Job Templates");
215 ?>
216  <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
217  <input type="hidden" name="act" value="<?php echo $act ?>">
218  <br>&nbsp;
219  <br>
220  <center>
221  <table cellpadding="3" cellspacing="0" border="0" width="500" class="dmsbg"><tr><td>
222  <table cellpadding="1" cellspacing="0" border="0" width="100%" bgcolor=white>
223  <tr>
224  <td colspan="7" class="bar" align="center">
225  <?php echo strtoupper($formmode); ?> CU Job Template
226  </td>
227  </tr>
228  <?php
229  if (strlen($form_err) > 0) {
230  print <<< form_error
231  <tr>
232  <td class='err' colspan='6' align='center'>
233  Errors were found saving the information. Please review errors and try again<br>
234  $form_err<br>
235  </td>
236  </tr>
237 form_error;
238  } elseif (strlen($form_msg) > 0) {
239  print <<< form_error
240  <tr>
241  <td class='msg' colspan='6' align='center'>
242  $form_msg
243  </td>
244  </tr>
245 form_error;
246  }
247  ?>
248  <tr>
249  <td nowrap colspan='3' align="right" class="hdr" width="10%">
250  CU Job Template<sup>*</sup>:
251  </td>
252  <td nowrap colspan="4" class='dtl' width="90%">
253  <?php
254  $value = "";
255  if ($num_rows > 0) {
256  $value = htmlspecialchars(trim($cuissues_row->code));
257  } else {
258  $value = set_string($iss_code);
259  }
260  ?>
261  <input type="text" name="iss_code" size="50" maxlength="80" value="<?php echo $value?>">
262  <input type="hidden" name="iss_id" value="<?php echo $iss_id ?>">
263  </td>
264  </tr>
265  <tr>
266  <td nowrap colspan='3' align="right" class="hdr" width="10%">
267  Auto-Generate for this Product:
268  </td>
269  <td nowrap colspan="4" class='dtl' width="90%">
270  <?php
271  $value = "";
272  if ($num_rows > 0) {
273  $value = htmlspecialchars(trim($cuissues_row->gen_for_product));
274  } else {
275  $value = set_string($iss_prod);
276  }
277  ?>
278  <select name="iss_prod">
279  <option value="">No Product Selected</option>
280  <?php
281  // first get the codes already in the list
282  $sql = "SELECT DISTINCT gen_for_product FROM cuissues";
283  $prod_rs = db_query($sql, $link);
284  $prod_row = 0;
285  $inUseList = array();
286  while ($row = db_fetch_array($prod_rs, $prod_row++)) {
287  $inUseList[] = trim( $row["gen_for_product"] );
288  }
289 
290  $sql = "SELECT *
291  FROM cuprodlist
292  ORDER BY home_cu_code ";
293  $hcu_rs = db_query($sql, $link);
294  $prod_row = 0;
295  while ($hcu_row = db_fetch_array($hcu_rs, $prod_row++)) {
296  $hcu_row['home_cu_code'] = trim($hcu_row['home_cu_code']);
297  $selected = ($hcu_row['home_cu_code'] == $value ? "SELECTED" : "");
298 
299  if ( in_array( $hcu_row["home_cu_code"], $inUseList ) &&
300  $selected === "" ) continue;
301 
302  $hcu_row['home_cu_desc'] = dms_disphtml($hcu_row['home_cu_desc']);
303  print "<option value=\"{$hcu_row['home_cu_code']}\" $selected >{$hcu_row['home_cu_desc']}</option>\n";
304  }
305  db_free_result($hcu_rs);
306  ?>
307  </select>
308  </td>
309  </tr>
310  <tr>
311  <td nowrap colspan='3' align="right" class="hdr" width="10%">
312  Default Owner<sup>*</sup>:
313  </td>
314  <td nowrap colspan="4" class='dtl' width="90%">
315  <?php
316  $value = "";
317  if ($num_rows > 0) {
318  $value = htmlspecialchars(trim($cuissues_row->owner));
319  } else {
320  $value = set_string($iss_owner);
321  }
322  ?>
323  <select name="iss_owner">
324  <option value="">No Owner Selected</option>
325  <?php
326  $sql = "SELECT user_name
327  FROM dmsmonitorusers
328  ORDER BY user_name ";
329  $hcu_rs = db_query($sql, $link);
330  $owner_row = 0;
331  $savedUsers = array();
332  while ($hcu_row = db_fetch_array($hcu_rs, $owner_row++)) {
333  $selected = (trim($hcu_row['user_name']) == $value ? "SELECTED" : "");
334  print "<option value=\"{$hcu_row['user_name']}\" $selected >{$hcu_row['user_name']}</option>\n";
335 
336  $savedUsers[] = $hcu_row['user_name'];
337  }
338  db_free_result($hcu_rs);
339  ?>
340  </select>
341  </td>
342  </tr>
343  <tr>
344  <td nowrap colspan='3' align="right" class="hdr" width="10%">
345  </td>
346  <td nowrap colspan="4" class='dtl' width="90%">
347  <sup>*</sup>Required fields
348  </td>
349  </tr>
350  <tr>
351  <td colspan=7 nowrap align="right" class="hdr">
352  <a href="/hcuadm/cuilist.prg">Return to Monitor</a>
353  </td>
354  </tr>
355  </tr>
356  <tr>
357  <td colspan=7 nowrap align="center" class="bar">
358  Items Required for Job Template
359  </td>
360  </tr>
361  <tr>
362  <td colspan=7 nowrap align="center" class="dtl" style="font-size:small;">
363  (If wanting to indent a new task with a new parent, please save first so have ids to work with.)
364  </td>
365  </tr>
366  <tr>
367  <td nowrap align="left" class="hdr" width="5%">
368  Row
369  </td>
370  <td nowrap align="left" class="hdr" width="5%">
371  Task
372  </td>
373  <td nowrap align="left" class="hdr" width="25%">
374  Title
375  </td>
376  <td nowrap align=left class='hdr' width="60%">
377  Description
378  </td>
379  <td nowrap align=left class='hdr' width="10%">
380  Owner
381  </td>
382  <td nowrap align=left class='hdr' width="15%">
383  Sales Item
384  </td>
385  <td class="hdr" width="10%">Delete?</td>
386  </tr>
387  <input type="hidden" name="row_to_move" value="">
388  <input type="hidden" name="direction_to_move" value="">
389  <script language="javascript">
390  <!--
391  function move_row(direction, row_num) {
392  // --- direction is the direction to move (UP, DOWN)
393  // --- row_num is the row number to move
394  document.forms[0].row_to_move.value = row_num;
395  document.forms[0].direction_to_move.value = direction;
396 
397  document.forms[0].submit();
398  return true;
399  }
400  // -->
401  </script>
402  <style>
403  .salesItemDDL {
404  width: 150px;
405  }
406  .salesItemDDL option {
407  text-overflow: ellipsis;
408  width: 150px;
409  }
410  </style>
411  <?php
412  $RGB = "odd";
413  $addblankrows = 0;
414 
415 
416  if (isset($total_rows)) {
417  // Loop here the number of times we need to see the detail, building a structure with all the rows
418  $row_idx = 0;
419  $field_idx = 0;
420  $row_up = 0;
421  $row_dwn = 0;
422  $skip_rows = 1;
423  $taskArray = array();
424  $lastParent = 0;
425  for ($loop_idx = 1; $loop_idx <= $total_rows; $loop_idx++) {
426  $row_idx = $loop_idx + $row_up; // THIS IS ADJUST ON UP MOVEMENTS
427  $field_idx = $loop_idx + $row_dwn;
428  // handle the case for moving a row up
429 
430 
431  // *** CHECK FOR MOVING A ROW UP -- AND PRINT IF FOUND
432  if (($direction_to_move == "UP" &&
433  intval($row_to_move) > $skip_rows) &&
434  intval($row_to_move) == ($loop_idx + $skip_rows)) {
435  $taskArray[] = array( "id" => isset(${"item_id_" . ($row_idx + $skip_rows)}) ? intval(${"item_id_" . ($row_idx + $skip_rows)}) : 0,
436  "parent" => isset(${"item_parent_" . ($row_idx + $skip_rows)}) ? ${"item_parent_" . ($row_idx + $skip_rows)} : "",
437  "title" => isset(${"item_title_" . ($row_idx + $skip_rows)}) ? ${"item_title_" . ($row_idx + $skip_rows)} : "",
438  "desc" => isset(${"item_desc_" . ($row_idx + $skip_rows)}) ? ${"item_desc_" . ($row_idx + $skip_rows)} : "",
439  "owner" => isset(${"item_owner_" . ($row_idx + $skip_rows)}) ? ${"item_owner_" . ($row_idx + $skip_rows)} : "",
440  "del" => isset(${"item_del_" . ($row_idx + $skip_rows)}) ? ${"item_del_" . ($row_idx + $skip_rows)} : "",
441  "sales_item_id" => isset(${"sales_item_" . ($row_idx + $skip_rows)}) ? intval(${"sales_item_" . ($row_idx + $skip_rows)}) : 0 );
442 // print_item_line($row_idx, ${"item_id_" . ($row_idx + $skip_rows)}, ${"item_parent_" . ($row_idx + $skip_rows)},
443 // ${"item_title_" . ($row_idx + $skip_rows)}, ${"item_desc_" . ($row_idx + $skip_rows)},
444 // ${"item_owner_" . ($row_idx + $skip_rows)}, ${"item_del_" . ($row_idx + $skip_rows)}, $RGB, $savedUsers);
445  $row_up = 1;
446  $row_idx = $loop_idx + $row_up;
447  $RGB = ($RGB == "odd" ? "even" : "odd");
448  }
449 
450 
451 
452  // *** CHECK FOR MOVING A LINE DOWN
453  if (($direction_to_move == "DOWN" &&
454  intval($row_to_move) > 0) &&
455  intval($row_to_move) == $loop_idx &&
456  intval($row_to_move) < $total_rows) {
457  $row_dwn = 1; // ADJUST THE NEXT ROW TO PRINT VALUE
458  $field_idx = $loop_idx + $row_dwn;
459  }
460 
461  // check for making a sub-task (first row cannot be a sub-task)
462  if ( $direction_to_move == "RIGHT" &&
463  intval( $row_to_move ) > 1 &&
464  intval( $row_to_move ) == $loop_idx ) {
465  // prior rows already in the taskArray
466  $taskArray[] = array( "id" => isset(${"item_id_" . ($row_idx)}) ? intval(${"item_id_" . ($row_idx)}) : 0,
467  "parent" => $lastParent,
468  "title" => isset(${"item_title_" . ($row_idx)}) ? ${"item_title_" . ($row_idx)} : "",
469  "desc" => isset(${"item_desc_" . ($row_idx)}) ? ${"item_desc_" . ($row_idx)} : "",
470  "owner" => isset(${"item_owner_" . ($row_idx)}) ? ${"item_owner_" . ($row_idx)} : "",
471  "del" => isset(${"item_del_" . ($row_idx)}) ? ${"item_del_" . ($row_idx)} : "",
472  "sales_item_id" => isset(${"sales_item_id_" . ($row_idx)}) ? intval(${"sales_item_id_" . ($row_idx)}) : 0 );
473  }
474 
475  // check for elevating to a task
476  if ( $direction_to_move == "LEFT" &&
477  intval( $row_to_move ) == $loop_idx ) {
478  // just set parent to 0
479  $taskArray[] = array( "id" => isset(${"item_id_" . ($row_idx)}) ? intval(${"item_id_" . ($row_idx)}) : 0,
480  "parent" => 0,
481  "title" => isset(${"item_title_" . ($row_idx)}) ? ${"item_title_" . ($row_idx)} : "",
482  "desc" => isset(${"item_desc_" . ($row_idx)}) ? ${"item_desc_" . ($row_idx)} : "",
483  "owner" => isset(${"item_owner_" . ($row_idx)}) ? ${"item_owner_" . ($row_idx)} : "",
484  "del" => isset(${"item_del_" . ($row_idx)}) ? ${"item_del_" . ($row_idx)} : "",
485  "sales_item_id" => isset(${"sales_item_id_" . ($row_idx)}) ? intval(${"sales_item_id_" . ($row_idx)}) : 0 );
486  }
487 
488  // **** PRINT THE REGULAR LINE
489  if ($direction_to_move == "" ||
490  ($direction_to_move == "UP" && intval($row_to_move) <= 1) ||
491  ($direction_to_move == "UP" && intval($row_to_move) != $loop_idx) ||
492  ($direction_to_move == "DOWN" && $loop_idx != (intval($row_to_move) + $skip_rows)) ||
493  ($direction_to_move == "RIGHT" && (intval( $row_to_move ) != $loop_idx)) ||
494  ($direction_to_move == "RIGHT" && (intval( $row_to_move ) == 1)) ||
495  ($direction_to_move == "LEFT" && (intval( $row_to_move ) != $loop_idx)) ) {
496  $taskArray[] = array( "id" => isset(${"item_id_" . $field_idx}) ? intval(${"item_id_" . $field_idx}) : 0,
497  "parent" => isset(${"item_parent_" . $field_idx}) ? ${"item_parent_" . $field_idx} : "",
498  "title" => isset(${"item_title_" . $field_idx}) ? ${"item_title_" . $field_idx} : "",
499  "desc" => isset(${"item_desc_" . $field_idx}) ? ${"item_desc_" . $field_idx} : "",
500  "owner" => isset(${"item_owner_" . $field_idx}) ? ${"item_owner_" . $field_idx} : "",
501  "sales_item_id" => isset(${"sales_item_id_" . $field_idx}) ? intval(${"sales_item_id_" . $field_idx}) : 0,
502  "del" => isset(${"item_del_" . $field_idx}) ? ${"item_del_" . $field_idx} : "" );
503 // print_item_line($row_idx, ${"item_id_" . $field_idx}, ${"item_parent_" . ($row_idx + $skip_rows)},
504 // ${"item_title_" . $field_idx} , ${"item_desc_" . $field_idx},
505 // ${"item_owner_" . $field_idx}, ${"item_del_" . $field_idx}, $RGB, $savedUsers);
506  $RGB = ($RGB == "odd" ? "even" : "odd");
507  }
508 
509 
510  // *** HERE POSSIBLY PRINT THE ROW MOVING DOWN
511  if (($direction_to_move == "DOWN" && intval($row_to_move) > 0) && intval($row_to_move) == ($loop_idx - $skip_rows)) {
512  $taskArray[] = array( "id" => isset(${"item_id_" . ($row_idx - $skip_rows)}) ? ${"item_id_" . ($row_idx - $skip_rows)} : 0,
513  "parent" => isset(${"item_parent_" . ($row_idx - $skip_rows)}) ? ${"item_parent_" . ($row_idx - $skip_rows)} : "",
514  "title" => isset(${"item_title_" . ($row_idx - $skip_rows)}) ? ${"item_title_" . ($row_idx - $skip_rows)} : "",
515  "desc" => isset(${"item_desc_" . ($row_idx - $skip_rows)}) ? ${"item_desc_" . ($row_idx - $skip_rows)} : "",
516  "owner" => isset(${"item_owner_" . ($row_idx - $skip_rows)}) ? ${"item_owner_" . ($row_idx - $skip_rows)} : "",
517  "sales_item_id" => isset(${"sales_item_id_" . ($row_idx - $skip_rows)}) ? intval(${"sales_item_id_" . ($row_idx - $skip_rows)}) : 0,
518  "del" => isset(${"item_del_" . ($row_idx - $skip_rows)}) ? ${"item_del_" . ($row_idx - $skip_rows)} : "");
519 // print_item_line($row_idx, ${"item_id_" . ($loop_idx - $skip_rows)}, ${"item_parent_" . ($row_idx - $skip_rows)},
520 // ${"item_title_" . ($loop_idx - $skip_rows)} , ${"item_desc_" . ($loop_idx - $skip_rows)},
521 // ${"item_owner_" . ($loop_idx - $skip_rows)}, ${"item_del_" . ($loop_idx - $skip_rows)}, $RGB, $savedUsers);
522  $row_dwn = 0;
523  $RGB = ($RGB == "odd" ? "even" : "odd");
524  //$row_idx = $loop_idx + $row_dwn;
525  }
526 
527 
528  // *** RESET ANY VALUES AFTER THE ADJUSTED ROW HAS BEEN DEALT WITH
529  if (($direction_to_move == "UP" && intval($row_to_move) == $loop_idx)) {
530  $row_up = 0;
531  }
532 
533  // see if the task just added is a parent or not
534  if ( $taskArray[count($taskArray)-1]["parent"] == 0 ) {
535  $lastParent = $taskArray[count($taskArray)-1]["id"];
536  }
537  }
538 
539  // make sure first task is never a sub-task
540  $taskArray[0]["parent"] = 0;
541 
542  // *** END OF LOADING FROM ITSELF
543  } else {
544  $total_rows = 0;
545  // LOAD FROM THE DATABASE
546  $sql = "SELECT *
547  FROM cuissuesitem
548  WHERE issue_id = '$load_issue_id'
549  ORDER BY view_order ";
550  $item_rs = db_query($sql, $link);
551  $item_rows = 0;
552  while ($item_row = db_fetch_array($item_rs, $item_rows++)) {
553  $taskArray[] = array( "id" => $item_row['item_id'],
554  "parent" => $item_row['parent'],
555  "title" => trim(dms_disphtml($item_row['title'])),
556  "desc" => trim(dms_disphtml($item_row['item_desc'])),
557  "owner" => trim(dms_disphtml($item_row['owner'])),
558  "sales_item_id" => intval(dms_disphtml($item_row['sales_item_id'])),
559  "del" => "" );
560 // print_item_line($item_rows, $item_row['item_id'], $item_row['parent'],
561 // dms_disphtml($item_row['title']), dms_disphtml($item_row['item_desc']),
562 // dms_disphtml($item_row['owner']), "", $RGB, $savedUsers);
563  $RGB = ($RGB == "odd" ? "even" : "odd");
564  $total_rows++;
565  }
566  db_free_result($item_rs);
567  // When loading from database -- Load 3 extra spots
568  $addblankrows = 3;
569  }
570  if (isset($addRows) && isset($btnAddRows)) {
571  $addblankrows = $addRows;
572  }
573  if ($addblankrows > 0) {
574  // Add that many rows
575  for ($loop_idx = 1; $loop_idx <= $addblankrows; $loop_idx++) {
576  $total_rows++;
577  $taskArray[] = array( "id" => "",
578  "parent" => 0,
579  "title" => "",
580  "desc" => "",
581  "owner" => "",
582  "sales_item_id" => 0,
583  "del" => "" );
584 // print_item_line($total_rows, "", 0, "" , "", "", "", $RGB, $savedUsers);
585  $RGB = ($RGB == "odd" ? "even" : "odd");
586  }
587  }
588 
589  $prodId = isset($iss_prod) && trim($iss_prod) != "" ? strtolower(set_string($iss_prod)) : strtolower(trim($cuissues_row->gen_for_product));
590  $issueId = isset($iss_id) && trim($iss_id) != "" ? intval($iss_id) : 0;
591  $sql = "select si.id, si.display_name, si.billing_template, ii.issue_id, si.billing_system_id from cubillsalesitem si
592  left join cuissuesitem ii on si.id = ii.sales_item_id
593  where lower(prod_id) = '$prodId' and (ii.issue_id is null or ii.issue_id = $issueId) ";
594 
595  $results = db_query($sql, $link);
596  $savedSalesItems = array();
597  $usedSalesItemsInTemplate = array();
598  $setupRecurring = getSetupRecurring();
599  $thisI = 0;
600  while ($thisRow = db_fetch_array($results, $thisI++)) {
601  $setupLabel = $setupRecurring[$thisRow["billing_system_id"]];
602  if (!isset($setupLabel) || $setupLabel != "triggered") {
603  continue;
604  }
605  $template = HCU_JsonDecode($thisRow["billing_template"]);
606  $text = trim($thisRow["display_name"]);
607  $value = trim($thisRow["id"]);
608 
609  switch(trim($thisRow["issue_id"])) {
610  case $issueId:
611  $usedSalesItemsInTemplate[$value] = $text;
612  break;
613  case "":
614  $savedSalesItems[$value] = $text;
615  break;
616  }
617  }
618  db_free_result($results);
619 
620  // now display all the rows
621  $parentNumber = 0;
622  $childNumber = 0;
623  for ( $i = 0; $i < count( $taskArray ); $i++ ) {
624  if ( $taskArray[$i]["parent"] == 0 ) {
625  $parentNumber++;
626  $childNumber = 0;
627  } else {
628  $childNumber++;
629  }
630 
631  // start the rows at 1
632  print_item_line($i + 1, $parentNumber, $childNumber, $taskArray[$i]['id'], $taskArray[$i]['parent'],
633  $taskArray[$i]['title'], $taskArray[$i]['desc'],
634  $taskArray[$i]['owner'], $taskArray[$i]['del'], $taskArray[$i]['sales_item_id'], $RGB, $savedUsers, $savedSalesItems, $usedSalesItemsInTemplate);
635 
636  $RGB = ($RGB == "odd" ? "even" : "odd");
637  }
638  ?>
639 
640  <tr>
641  <td colspan=7 nowrap align="right" class="dtl">
642  <hr>
643  </td>
644  </tr>
645  <tr>
646  <td align="left" colspan='2' class="dtl">
647  <input type="submit" name="saveForm" value="Save Job Template">
648  </td>
649  <td nowrap align="left" class="dtl">
650  <input type="button" name="Cancel" Value="Cancel" onClick="document.location='<?php echo $_SERVER['PHP_SELF']; ?>'">
651  </td>
652  <td class="dtl">&nbsp;</td>
653  <td nowrap align="right" class="dtl" colspan="3">
654  <input type="hidden" name="total_rows" value="<?php echo $total_rows; ?>">
655  <select name="addRows" size="1">
656  <option value="1">1</option>
657  <option value="2">2</option>
658  <option value="3">3</option>
659  <option value="4">4</option>
660  <option value="5">5</option>
661  </select>
662  <input type="submit" name="btnAddRows" value="Add Item Rows">
663  </td>
664  </tr>
665  </table>
666  </td></tr></table>
667 
668  <?php // If the error value is here then print it at the end
669  break;
670  case "2":
671  cu_header("CU Job Templates");
672  ?>
673  <form>
674 
675  <?php
676  // Connect to the data and retrieve the current list of Home CU Products
677  $query = "SELECT *
678  FROM cuissues cui
679  LEFT JOIN cuprodlist cupl ON cupl.home_cu_code = cui.gen_for_product
680  ORDER BY code";
681  $prod_result = db_query($query, $link);
682 
683  ?>
684 
685  <!-- Print out the top of the table -->
686 
687  <table border="0" cellpadding="3" cellspacing="0" align="center" class="dmsbg" width="500"><tr><td>
688  <table border="0" cellpadding="1" cellspacing="0" align="center" width="100%" bgcolor=white>
689  <tr>
690  <td colspan="5" class="bar" align="center">
691  CU JOB TEMPLATE LIST
692  </td>
693  </tr>
694 
695  <?php
696  if (strlen($form_msg) > 0) {
697  print <<< print_html
698  <tr>
699  <td class='msg' colspan='4' align='center'>
700  $form_msg
701  </td>
702  </tr>
703 print_html;
704  } elseif (strlen($form_err) > 0) {
705  print <<< print_html
706  <tr>
707  <td class='err' colspan='4' align='center'>
708  $form_err
709  </td>
710  </tr>
711 print_html;
712  }
713  ?>
714  <tr>
715  <td class="hdr" align="left">
716  JOB TEMPLATE CODE
717  </td>
718  <td class="hdr" align="left">
719  DEFAULT OWNER
720  </td>
721  <td class="hdr" align="left">
722  LINKED PRODUCT
723  </td>
724  <td class="hdr" align="center">
725  Select
726  </td>
727  </tr>
728  <?php
729  $RGB = "odd";
730  $row = 0;
731  while ($prod_row = db_fetch_object($prod_result, $row)):
732  $row++;
733  ?>
734  <tr class="<?php echo $RGB; ?>">
735  <td nowrap >
736  <?php echo trim($prod_row->code) ?>
737  </td>
738  <td nowrap >
739  <?php echo trim($prod_row->owner) ?>
740  </td>
741  <td nowrap >
742  <?php echo trim($prod_row->home_cu_desc) ?>
743  </td>
744  <td nowrap >
745  <a href="<?php echo $_SERVER['PHP_SELF']; ?>?act=1&iss_id=<?php echo trim($prod_row->issue_id) ?>">Edit</a>
746  &nbsp;|&nbsp; <a href="<?php echo $_SERVER['PHP_SELF']; ?>?act=4&iid=<?php echo $prod_row->issue_id; ?>">Delete</a>
747  </td>
748  </tr>
749  <?php
750  $RGB = ($RGB == "odd" ? "even" : "odd");
751  endwhile; ?>
752 
753  <tr>
754  <td colspan="3">
755  <a href="<?php echo $_SERVER['PHP_SELF']; ?>?act=1">Add CU Job Template</a>
756  &nbsp;|&nbsp;
757  <a href="<?php echo $infourl ?>/hcuadm/cuilist.prg" target="parent">Return to Monitor</a>
758  </td>
759  </tr>
760  </table>
761  </td></tr></table>
762 <?php
763  break;
764  case "4":
765  // This is the confirmation screen for the DELETE Job Template code
766 
767  // This script will confirm the deletion of a record,
768  // upon success or cancel the form will go to the next_page
769  // field that can be passed to the form
770 
771  // Expected the 'iid' value to be passed in, which is the id of the cuissues record to be deleted
772 
773  // Upon returning to the screen a msg parameter will be passed along describing the message, giving the
774  // form the option of showing the message
775 
776  $self = $_SERVER['PHP_SELF'];
777 
778  $return_msg = "";
779  $sql = "SELECT *
780  FROM cuissues
781  WHERE issue_id = " . intval($iid);
782  $del_rs = db_query($sql, $link);
783  $del_row = db_fetch_array($del_rs, 0);
784  cu_header("Delete CU Issues");
785  ?>
786  <center>
787  <table cellpadding="3" cellspacing="0" border="0" width="500" class="dmsbg"><tr><td>
788  <form action="<?php echo $self; ?>" method="post">
789  <input type="hidden" name="iid" value="<?php echo $del_row['issue_id']; ?>">
790  <input type="hidden" name="act" value="4">
791  <table border="0" cellpadding="1" cellspacing="0" align="center" width="100%" bgcolor=white>
792  <tr><td class="bar" colspan="2" align="center">Confirm CU Job Template Deletion</td></tr>
793  <tr>
794  <td class="ahd" colspan="2" align='center'>
795  Hi there, you are about to delete the job template '<?php echo dms_disphtml($del_row['code']); ?>' from the Job Template table.<br>
796  </td>
797  </tr>
798 <!--
799  <tr><td class="ileft" colspan="2" align="center">&nbsp;</td></tr>
800  <tr>
801  <td width="20%" class="ileft">
802  Issue Code:
803  </td>
804  <td class="ileft">
805  <?php echo dms_disphtml($del_row['code']); ?>
806  </td>
807  </tr>
808 -->
809  <tr><td colspan="2" class="ahd"><hr></td></tr>
810  <tr>
811  <td class="ahd" colspan="2" align='center'>
812  You are only one step away from deleting this record.<br>
813  Are you sure you want to continue?<br>
814  <input type="submit" name="btn_act" value="Yes, delete the record">
815  <input type="submit" name="btn_stop" value="No, I changed my mind">
816  </td>
817  </tr>
818  </table>
819  </form>
820  </td></tr></table>
821 <?php
822  break;
823  default:
824  cu_header("Error Displaying Form");
825  print ("<form>");
826  printError("Requested form not found!<br>Cancelling action.");
827  endswitch;
828  ?>
829  </form>
830  </body>
831 </html>
832 
833 <?php
834  function print_item_line($row_id, $taskNum, $childNum, $field_id, $parentId, $title_val, $desc_val, $taskOwner, $del_val, $salesItemId, $row_class, $ownerList,
835  $savedSalesItems, $usedSalesItemsInTemplate) {
836  // This is the function to add a line to the row
837 // echo "PRINT LINE: $row_id<br>";
838  $del_val = ($del_val == "Y" ? "CHECKED" : "");
839 //print "<br>print row: $row_id, $taskNum, $childNum, $field_id, $parentId, $title_val, $desc_val, $taskOwner, $del_val, $row_class";
840 
841  // Always print the shift UP and DOWN options -- but if at the top or bottom it will be
842  // ignored
843  $shift_up = "<a href=\"javascript:move_row('UP', '$row_id');\" onMouseOver=\"status='Shift Row Up'; return true;\" onMouseOut=\"status='';\"><img border=0 src=\"/monitor/images/admin_up.gif\" alt=\"Move Up\"></a>";
844  $shift_down = "<a href=\"javascript:move_row('DOWN', '$row_id');\" onMouseOver=\"status='Shift Row Down'; return true;\" onMouseOut=\"status='';\"><img border=0 src=\"/monitor/images/admin_down.gif\" alt=\"Move Down\"></a>";
845 
846  // always show the shift LEFT and RIGHT options -- but if left or right the same direction will be ignored
847  $shiftLeft = "<a href=\"javascript:move_row('LEFT', '$row_id');\" onMouseOver=\"status='Shift Row Left'; return true;\" onMouseOut=\"status='';\" style=\"text-decoration:none;\">&lt;</a>";
848  $shiftRight = "<a href=\"javascript:move_row('RIGHT', '$row_id');\" onMouseOver=\"status='Shift Row Right'; return true;\" onMouseOut=\"status='';\" style=\"text-decoration:none;\">&gt;</a>";
849 
850  if ( $childNum > 0 ) {
851  $rowString = "&nbsp;&nbsp;&nbsp;$taskNum.$childNum";
852  } else {
853  $rowString = "$taskNum";
854  }
855 
856  $salesItemOptions= array();
857  $found= false;
858  if ($salesItemId != 0 && !isset($savedSalesItems[$salesItemId]))
859  {
860  $salesItemOptions[]= "<option value='$salesItemId' selected=selected>" . (isset($usedSalesItemsInTemplate[$salesItemId]) ? $usedSalesItemsInTemplate[$salesItemId] : $salesItemId) . "</option>";
861  $found= true;
862  }
863  foreach($savedSalesItems as $value => $text)
864  {
865  $selected= "";
866  if ($salesItemId == $value)
867  {
868  $found= true;
869  $selected= "selected=selected";
870  }
871  $salesItemOptions[]= "<option value='$value' $selected>$text</option>";
872  }
873  $selected= $found ? "" : "selected=selected";
874  array_splice($salesItemOptions, 0,0, "<option value='0' $selected>None</option>");
875  $salesItemsDDL= "<select name='sales_item_id_$row_id' class='salesItemDDL'>" . implode("\n", $salesItemOptions) . "</select>";
876 
877  print <<< Print_Row
878  <tr class="$row_class">
879  <td class="usu" style="font-style:italic;">
880  $row_id
881  </td>
882  <td class="usu">
883  $rowString
884  </td>
885  <td nowrap align="left" class="">
886  <input type="hidden" name="item_id_$row_id" value="$field_id">
887  <input type="hidden" name="item_parent_$row_id" value="$parentId">
888  <input type="text" name="item_title_$row_id" size="35" maxlength="50" value="$title_val">
889  </td>
890  <td nowrap align=left class=''>
891  <textarea rows=3 cols=40 name="item_desc_$row_id">$desc_val</textarea>
892  </td>
893  <td nowrap align="left" class="">
894  <select name="item_owner_$row_id">"
895  <option value="">Default Owner</option>
896 Print_Row;
897  for ( $i = 0; $i < count( $ownerList ); $i++ ) {
898  $selected = (trim($ownerList[$i]) == $taskOwner ? "SELECTED" : "");
899  print "<option value=\"{$ownerList[$i]}\" $selected >{$ownerList[$i]}</option>\n";
900  }
901 
902  print <<< Print_Row
903  </select>
904  </td>
905  <td nowrap align="left" class="">$salesItemsDDL</td>
906  <td valign="top"nowrap>
907  <input type="checkbox" name="item_del_$row_id" value="Y" $del_val>
908  $shiftLeft
909  $shift_down
910  $shift_up
911  $shiftRight
912  </td>
913  </tr>
914 Print_Row;
915  }
916 ?>